php barcelona monthly talk feb 2015
TRANSCRIPT
![Page 1: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/1.jpg)
(println "Hello World! :)")
![Page 2: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/2.jpg)
DDD as an implementation detail
Eloi PochSergi González
![Page 3: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/3.jpg)
Who$are$we?$$
!es.linkedin.com/in/eloipoch/$
$
$@eloipoch$
Eloi!Poch!!Technical!Lead!at!@Akamon!• So8ware$Developer$• Clojure$developer$wannabe$• Want$to$code$in$Castefa$beach$while$drinking$wine$
![Page 4: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/4.jpg)
(conj '(1 2 3) 4)
![Page 5: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/5.jpg)
Who$are$we?$$
!es.linkedin.com/in/sergigp/$
$
$“SergiGP$
Sergi!!Technical!Lead!at!@Akamon!• So<ware$Developer$• Chief$Trolling$Officer$• Two$animals$remaining$to$have$an$urban$zoo$
![Page 6: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/6.jpg)
![Page 7: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/7.jpg)
Akamon
![Page 8: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/8.jpg)
A little bit on Akamon before we deal with the technical stuff
![Page 9: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/9.jpg)
We#develop#Social#Casino#Games#
![Page 10: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/10.jpg)
Por$olio'of'Facebook'games'
![Page 11: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/11.jpg)
Por$olio'of'Mobile'apps'
![Page 12: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/12.jpg)
Recently(launched(a(new(Casino(Suite(
![Page 13: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/13.jpg)
Technically …
![Page 14: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/14.jpg)
Flash Client Game Server Backend
AS3 Nova
Java JReactive & Vertx
PHP Horus
![Page 15: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/15.jpg)
![Page 16: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/16.jpg)
@eloipoch @jordillonch @SergiGP
@jorgeavila_ss @jdiezc @jvalduvieco @amassa5
Who we are? The backend team
![Page 17: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/17.jpg)
Development Problems
![Page 18: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/18.jpg)
Our expectations…
![Page 19: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/19.jpg)
PerformanceBig DataDifficult AlgorithmsConcurrencyReal time analyticsScalability
![Page 20: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/20.jpg)
The ugly truth…
![Page 21: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/21.jpg)
Technical Problems
![Page 22: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/22.jpg)
Code ComplexityBig ball of mudShared StateCoupling
![Page 23: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/23.jpg)
![Page 24: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/24.jpg)
& Non-Technical problems
![Page 25: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/25.jpg)
Different Cultures
![Page 26: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/26.jpg)
Tackling Complex CodeThe Philosophy
![Page 27: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/27.jpg)
Simple made Easy
![Page 28: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/28.jpg)
Complex((
One(role(
One(task(
not(a(single(opera2on(
(
OBJECTIVE
Hard(
Familiar,(near(your(
knowledge(
(
(
Simple(vs(Easy((
SUBJECTIVEOBJECTIVE
![Page 29: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/29.jpg)
Simple vs Easy
$mysqli = new mysqli("localhost", "horus", "olakease", “suite"); $mysqli->query("INSERT INTO users …”))
SIMPLE
EASY
/** * @ORM\Entity * @ORM\Table(name="product") */ class Product
![Page 30: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/30.jpg)
$sum = function ($carry, $item) { return $carry + $item; } array_reduce([1, 2, 3], $sum);
$acc = 0; foreach ([1, 2, 3] as $value) {
$acc += $value; }
SIMPLE
EASY
Simple vs EasySimple vs Easy
![Page 31: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/31.jpg)
$acc = 0; foreach ([1, 2, 3] as $value) {
$acc += $value; }
SIMPLE
EASY
(reduce + [1 2 3])
Simple vs EasySimple vs Easy
![Page 32: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/32.jpg)
Simplicity vs Easiness
• Easy to understand
• Easy to debug
• Easy to change, flexibility, maintenable
• Easy to use
• Hard to debug
• Hard to change
![Page 33: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/33.jpg)
Complected
• Something does more than one thing and you can’t split it easily
• Source of accidental complexity
• DON’T DO IT
![Page 34: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/34.jpg)
Essential ComplexityVS
Accidental Complexity
![Page 35: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/35.jpg)
Do not complect, compose
![Page 36: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/36.jpg)
Tackling Complex Code
The Theory
![Page 37: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/37.jpg)
Organisational level
![Page 38: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/38.jpg)
Pair Programming
![Page 39: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/39.jpg)
Pull Requests
![Page 40: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/40.jpg)
Code Reviews
![Page 41: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/41.jpg)
Continuous Integration
![Page 42: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/42.jpg)
Self Empowerment
Never ask for permission unless it
would be reckless not to
![Page 43: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/43.jpg)
Trust
Great teams are unafraid to air their dirty laundry, admit their mistakes, their weaknesses and their concerns
without fear. Patrick Lencioni
![Page 44: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/44.jpg)
Technical Level
![Page 45: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/45.jpg)
Lean Approach
![Page 46: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/46.jpg)
Any model/solution is provisional
![Page 47: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/47.jpg)
YAGNIYou Aren’t Gonna Need It
![Page 48: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/48.jpg)
DDD Concepts
![Page 49: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/49.jpg)
• DDD Tactical:
• Application Services
• Domain Services
• Domain Events
• Repositories
• AR & VO
• DDD Strategical:
• Modules
• Bounded Contexts
• SubDomains
• Context Maps
![Page 50: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/50.jpg)
CQRS Concepts
![Page 51: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/51.jpg)
![Page 52: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/52.jpg)
Hexagonal Architecture
![Page 53: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/53.jpg)
![Page 54: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/54.jpg)
TDD & BDD
![Page 55: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/55.jpg)
![Page 56: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/56.jpg)
Tackling Complex Code
The Practice
![Page 57: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/57.jpg)
Divide, Test & Conquer
![Page 58: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/58.jpg)
Product Entity Example
![Page 59: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/59.jpg)
ProductId
NameDescription
PriceCurrencyImage Url
CoinsStoreId
![Page 60: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/60.jpg)
Product
Product Descriptions
Product Prices
Stores
Product Benefits
Product Images
![Page 61: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/61.jpg)
ProductId
Product Description
Product Price
Stores
Product Benefit
Product Image
DescriptionName Currency
Amount
CoinsStoreId
Image Url
![Page 62: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/62.jpg)
ProductId
Product Description
Product Price
Stores
Product Benefit
Product Image
DescriptionName Currency
Amount
CoinsStoreId
Image Url
Product BC
![Page 63: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/63.jpg)
ProductId
Product Description
Product Price
Stores
Product Benefit
Product Image
DescriptionName Currency
Amount
CoinsStoreId
Image Url
Pricing/Sales BC
Product BC
![Page 64: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/64.jpg)
Product
Id
BenefitId
Product Price
ProductId
Amount
Currency
Product Description
ProductId
Name
Description
Product Benefit
Id
Amount
VirtualMoneyId
Product Store
ProductId
StoreId
![Page 65: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/65.jpg)
![Page 66: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/66.jpg)
HORUS
![Page 67: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/67.jpg)
Big Picture
• Directories: 773
• Files: 1501
• Lines of code: 113885
• Non-Comment Lines of Code: 88806 (80%)
• Average Class Length: 14 lines
• Average Method Length: 2 lines
• Cyclomatic Complexity / LLOC: 0.06
• Cyclomatic Complexity / Number of Methods: 1.21
HORUS
![Page 68: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/68.jpg)
Big Picture of our Code in Horus
• Directories: 773 / 558
• Files: 1501 / 1001
• Lines of code: 113885 / 41205
• Non-Comment Lines of Code: 88806 (80%) / 38045 (92%)
• Average Class Length: 14 lines / 5 lines
• Average Method Length: 2 lines / 2 lines
• Cyclomatic Complexity / LLOC: 0.06 / 0.03
• Cyclomatic Complexity / Number of Methods: 1.21 / 1.14
![Page 69: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/69.jpg)
![Page 70: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/70.jpg)
UserPostController Command Bus
UserRegistratorCommandHandler
UserRegistratorDomain Event
Publisher
UserRegisteredDomainEventSubscriber
UserAccountOpener
User UserRepository Event Subscribers
.
.
.
POST /users[
userId: 0db90987-5ce1-4683-bb05-7d1b5539cb0b]
Command Handlers
.
.
.
UserR
egisteredDom
ainEvent
User
HORUS
BASIC REQUEST
UserRegistrationCommand
UserRegistrationCommand
userIdanalyticsContextId
userIdanalyticsContextId
UserRegisteredDomainEvent
userId
analyticsContextId
id (Economy Account)
![Page 71: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/71.jpg)
UserPostController Command Bus
UserRegistratorCommandHandler
UserRegistratorDomain Event
Publisher
UserRegisteredDomainEventSubscriber
UserAccountOpener
User UserRepository Event Subscribers
.
.
.
POST /users[
userId: 0db90987-5ce1-4683-bb05-7d1b5539cb0b]
Command Handlers
.
.
.
UserR
egisteredDom
ainEvent
User
HORUS
BASIC REQUEST
UserRegistrationCommand
UserRegistrationCommand
userIdanalyticsContextId
userIdanalyticsContextId
UserRegisteredDomainEvent
userId
analyticsContextId
id (Economy Account)
UserModule
EconomyModule
![Page 72: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/72.jpg)
Operational
Analytics
Support
Marketing
DE
C
Q
Q
We are still COUPLED !!
![Page 73: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/73.jpg)
Operational
Analytics
Support
Marketing
HTTP
…
![Page 74: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/74.jpg)
Tackling Complex Code
The Conclusions
![Page 75: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/75.jpg)
Mistakes
• Do not store domain events
• Own libraries for CQRS & DDD
• Do not use Domain Services
• Domain events with wrong identifiers
• Couple App Services to Commands & Queries
• Not start earlier some Modules/Bounded Contexts
![Page 76: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/76.jpg)
Mistakes
• Let the DB guide us
• Let the framework guide us
![Page 77: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/77.jpg)
Problems
• Domain Events: Lost of order (async)
• Doctrine
• Unit Of Work + Integration Test = Fail
• Embedded: Identifier or not
• Behat: The Container
![Page 78: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/78.jpg)
Tips & Tricks
• Repositories:
• Just add, save and find
• Use of DQL implies the schema is too complex
• Controllers: 50 lines of code
• Application Services: Avoid business logic
• One step at time: Hex. Arch. -> DDD -> CQRS -> ES?
• Start it as a Module and promote it later to BC
![Page 79: PHP Barcelona Monthly Talk Feb 2015](https://reader035.vdocuments.mx/reader035/viewer/2022062420/55c29759bb61eb4e128b470f/html5/thumbnails/79.jpg)
TROLLTIMEQUESTIONS?
Akamon Developers