eventdrivenarchitecture
Post on 20-Oct-2014
2.640 views
DESCRIPTION
TRANSCRIPT
![Page 1: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/1.jpg)
DomainEvent Driven Architecture
Stefan Norberg,Head of Architecture at Unibet.com
twitter: @stnoremail: [email protected]: http://stnor.wordpress.com
![Page 2: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/2.jpg)
@stnor
• 17 years as an IT professional
• Has worked with most aspects of IT
• Operations & infrastructure• IT security• Systems development• Software architecture• Enterprise architecture
• Head of Architecture at Unibet
![Page 3: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/3.jpg)
Agenda
• Basics and EDA intro
• The SOA problem
• How Domain EDA completes SOA
• Implementation notes from Unibet
• What to tell your manager
![Page 4: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/4.jpg)
The three styles of interaction
Type of interaction Initiator Participants
Time-driven Time The specified systems
Request-driven Client Client and Server
Event-driven Event Open-ended
![Page 5: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/5.jpg)
Time driven
Fruitsystem
run inventory check every 60
mins
![Page 6: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/6.jpg)
Request driven
TarzanFruit
systemMe want three bananas!
![Page 7: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/7.jpg)
Event driven
“Tarzan took three bananas”
“Fruit system is low on bananas”
Fruitsystem
![Page 8: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/8.jpg)
5 Principles of EDA
• “Real-time” events as they happen at the producer
• Push notifications
• One-way “fire-and-forget”
• Immediate action at the consumers
• Informational (“someone logged in”), not commands (“audit this”)
![Page 9: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/9.jpg)
Typical EDA architecture
system system system
Event Bus
EventProducers
EventTransport
system system systemEvent
Consumers
![Page 10: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/10.jpg)
Main benefits of EDA
• Supports the business demands for better service (no batch, less waiting)
• No point-to-point integrations (fire & forget)
• Enables high performance, highly scalable systems
![Page 11: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/11.jpg)
The birth of a system
Customer
Shop
Inventory
![Page 12: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/12.jpg)
The monolith
PaymentCustomer
ReportingInventory
Shop
Newsletter
![Page 13: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/13.jpg)
SOA architecture #1
Shop Payment Newsletter
InventoryCustomer
DB Reporting
Divide the problem domains into separate systems
![Page 14: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/14.jpg)
SOA architecture #1
Shop Payment Newsletter
InventoryCustomer
DB Reporting
A lot of point to point integration...
![Page 15: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/15.jpg)
SOA architecture #2
Shop Payment Newsletter
Service Bus
InventoryCustomer
DB Reporting
Monolith?
![Page 16: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/16.jpg)
Let’s add fraud checks
Shop Payment Newsletter
Service Bus
InventoryCustomer
DB Reporting
fraud
fraud
![Page 17: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/17.jpg)
Let’s add a loyalty system
Shop Payment Newsletter
Service Bus
InventoryCustomer
DB ReportingLoyalty
fraud
fraud
![Page 18: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/18.jpg)
Integration ripple effect
Shop Payment Newsletter
Service Bus
InventoryCustomer
DB ReportingLoyalty
fraud
fraud
![Page 19: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/19.jpg)
Problem summary
• SOA is all about dividing domain logic into separate systems and exposing it as services
• Some domain logic will, by its very nature, be spread out over many systems
• The result is domain pollution and bloat in the SOA systems
![Page 20: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/20.jpg)
“It's really become clear to me in the last couple of years that we need a new building block and that is the Domain Events”
-- Eric Evans, QCon 2009
![Page 21: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/21.jpg)
Domain Events and SOA
• A Domain Event is something that happened that the domain expert cares about
• A SOA system’s primary focus should be on the domain and domain logic
![Page 22: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/22.jpg)
Domain EDA
• By exposing relevant Domain Events on a shared event bus we can isolate cross cutting functions to separate systems
![Page 23: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/23.jpg)
Domain EDA + SOA
Shop Payment Newsletter
Inventory Customer
Reporting
LoyaltyEvent Bus
![Page 24: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/24.jpg)
Domain EDA + SOA
Shop Payment Newsletter
Inventory Customer
Reporting
LoyaltyEvent Bus
BAM
Fraud
![Page 25: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/25.jpg)
“You complete me”
SOADomain EDA
![Page 26: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/26.jpg)
Example how Domain EDA decouples
![Page 27: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/27.jpg)
Trading system
model
Reporting system
model
Coupled integration
![Page 28: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/28.jpg)
Trading system
model v2
Reporting system
model
Coupled integration
![Page 29: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/29.jpg)
Trading system
model
Reporting system
model
domain events
I’m interested in buy, sell and market
status events
subscribe
Domain EDA integration
![Page 30: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/30.jpg)
Trading system
model v2
Reporting system
model
domain events
I’m interested in buy, sell and market
status events
subscribe
Domain EDA integration
![Page 31: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/31.jpg)
- “So what? I can do that with SOA...”
- “Yes, but can you do THIS?” (drumroll)
![Page 32: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/32.jpg)
Trading system
model v2
Reporting system
model
domain events
I’m interested in buy, sell and market
status events
subscribe
Trading system NG
model
domain events
Domain EDA integration
![Page 33: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/33.jpg)
Trading system
model v2
Reporting system
model
I’m interested in buy, sell and market
status events
subscribe
Trading system NG
model
domain events
Domain EDA integration
![Page 34: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/34.jpg)
Example how EDA scales
![Page 35: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/35.jpg)
Traditional SOA scalability issue
Order processing
200 tx/s
![Page 36: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/36.jpg)
Traditional SOA scalability issue
Order processing
Loyalty system
request/response
200 tx/s
![Page 37: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/37.jpg)
Traditional SOA scalability issue
Order processing
Loyalty system
200 tx/s
100 tx/s
request/response
![Page 38: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/38.jpg)
SOA: Weakest link dictates the peak throughput
of the system
Order processing
Loyalty system
100 tx/s
100 tx/s
request/response
![Page 39: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/39.jpg)
Order processing
Loyalty system
200 tx/s
100 tx/s
EDA: Weakest link dictates the sustained throughput
of the system
event
![Page 41: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/41.jpg)
MQ considerations
• Ordering
• Durability
• Performance
• Once and only once delivery
![Page 42: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/42.jpg)
Our requirements
• 1000 messages / second sustained
• Guaranteed delivery
• Easy to use client
![Page 43: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/43.jpg)
Brokers tested
• Lots of brokers tested
• ActiveMQ, OpenMQ, HornetQ, Websphere, Fiorano, RabbitMQ, QPID
• Second round
• ActiveMQ, OpenMQ and RabbitMQ
• Finally went for ActiveMQ - fitted our requirements/use case the best
![Page 44: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/44.jpg)
Testing brokers
• Killing brokers
• Flow control
• Slow consumers
• Durable / non-durable
• Small configuration change can have huge impact on throughput
![Page 45: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/45.jpg)
Payload considerations
![Page 46: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/46.jpg)
The smorgasbord
Name Standardized Schema support Binary Easy to use X-platform Std API
ASN.1
CSV
XML
JSON
Java serialization
Hessian
Protocol Buffers
BSON
Yes Yes Yes No Yes No
Partial No No No? Yes No
Yes Yes No Yes Yes DOM, SAX, XQUERY, XPATH
Yes No No Yes Yes No
No Partial Yes Yes No No
No Partial Yes Yes Yes No
No Yes Yes Yes Yes No
No No Yes Yes Yes No
![Page 47: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/47.jpg)
Domain events need schema support
Name Standardized Schema support Binary Easy to use X-platform Std API
ASN.1
CSV
XML
JSON
Java serialization
Hessian
Protocol Buffers
BSON
Yes Yes Yes No Yes No
Partial No No No? Yes No
Yes Yes No Yes Yes DOM, SAX, XQUERY, XPATH
Yes No No Yes Yes No
No Partial Yes Yes No No
No Partial Yes Yes Yes No
No Yes Yes Yes Yes No
No No Yes Yes Yes No
![Page 48: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/48.jpg)
+ Efficient, x-platform and easy to use
Name Standardized Schema support Binary Easy to use X-platform Std API
ASN.1
XML
Protocol Buffers
Yes Yes No No Yes No
Yes Yes No Yes Yes DOM, SAX, XQUERY, XPATH
No Yes Yes Yes Yes No
![Page 49: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/49.jpg)
Protocol Buffers
• Flexible, efficient, automated mechanism for serializing (binary)
• Schema support (.proto files)
• Language neutral
• Invented and used by Google Open Sourced in July 2008
![Page 50: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/50.jpg)
Examplenewuserevent.proto:
option java_package = "com.example.foo";message NewUserEvent { required string name = 1; required int32 id = 2; optional string email = 3;
enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; }
message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; }
repeated PhoneNumber phone = 4;}
![Page 51: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/51.jpg)
Generating Java Source
$ protoc --proto_path=IMPORT_PATH \ --java_out=DST_DIR \ path/to/file.proto
IMPORT_PATH specifies a directory in which to look for .proto files when resolving import directives.
If the DST_DIR ends in .zip or .jar, the compiler will write the output to a single ZIP-format archive file with the given name.
![Page 52: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/52.jpg)
Builders vs messages
NewUserEvent stefan = NewUserEvent.newBuilder() .setId(1337) .setName("Stefan Norberg") .setEmail(“[email protected]") .addPhone( NewUserEvent.PhoneNumber.newBuilder() .setNumber("+46 70 99 66 547") .setType(NewUserEvent.PhoneType.WORK)) .build();
• Messages classes are immutable
• Use builders to construct
![Page 53: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/53.jpg)
Evolving messages
• You cannot remove required fields
• New fields that you add should be optional or repeated
• New fields should have sensible defaults
• Prefix deprecated non-required fields with OBSOLETE_ (convention)
![Page 54: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/54.jpg)
Sample EDA producer
@AutowiredDomainEventPublisher publisher;
NewUserEvent stefan = NewUserEvent.newBuilder() .setId(1337) .setName("Stefan Norberg") .setEmail(“[email protected]") .addPhone( NewUserEvent.PhoneNumber.newBuilder() .setNumber("+46 70 99 66 547") .setType(NewUserEvent.PhoneType.WORK)) .build();
publisher.publish(stefan);
![Page 55: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/55.jpg)
Sample EDA consumerpublic class YourDomainListenerPOJO {
public void receive(LoginEvent loginEvent) {// do something
}
@Durable(clientId=”com.example.foo.bar”)public void receive(NewUserEvent newUserEvent) {
// do something}
}
<import resource=”classpath:spring-domain-events.xml />
<bean id=”domainEventListener” class=”com.foo.YourDomainListenerPOJO”/>
<domain-events:subscribe id=”eventSubscriber” subscriber=”domainEventListener”/>
![Page 56: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/56.jpg)
What to tell your manager
![Page 57: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/57.jpg)
What to tell your manager
• SOA+EDA will reduce time-to-market for new functionality
• SOA+EDA will enable a layer of high-value services that have a visible impact on the bottom line of the business
![Page 58: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/58.jpg)
Game changingvalue-add
![Page 59: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/59.jpg)
Complex Event Processing (CEP)
• 100% Event-driven
• Receives domain events
• Performs event correlation using a QL
• Fires domain events (“findings”)
![Page 60: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/60.jpg)
CEP Examples
Correlation(CEP)
events events “findings”
if there are no Mastercard deposits from France in 5 minutes during business hours,send NoDespositsEvent
if there are >30 failed logins using >5 accounts from the same ip within 2 minutes,block the ip for 24 hours
if customer with loyalty >= gold and puts goods in shopping cart for more than €200, send VIPShoppingEvent
if customer loses €2000 in the casino within 30 minutes and customer != highrollersend PotentialHighrollerEvent AND grant €200 casino premium
request/response“action”
![Page 61: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/61.jpg)
Business Process Management (BPM)
• Business control over definition and automation of business processes
• SOA services “orchestration”
• Processes can/should be started by domain events
![Page 62: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/62.jpg)
BPM example
EvaluateHighroller
Start
Profit > €5000
Manual investigation /
decision
Set VIP Status
Stop
Get Customer Info
decision?
Manager approval
Profit >€1000
approved?
Stop Stop
PotentialHighrollerEvent
CustomerSystem
![Page 63: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/63.jpg)
Business Activity Monitoring (BAM)
• Aggregation, analysis, and presentation of real time information about activities inside organizations and involving customers and partners
• BAM attempts to do for business processing what network management tools do for network operations
![Page 64: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/64.jpg)
![Page 65: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/65.jpg)
The real-time business eco system
Service Oriented Architecture (SOA)
Domain Event Driven Architecture (D-EDA)
Correlation(CEP)
Processes(BPM)
Monitoring(BAM)
Business Value
IT enhancements
Great business
IT systems
Great architecture
events
events
events
events
eventsrequest/response
request/response
![Page 66: EventDrivenArchitecture](https://reader034.vdocument.in/reader034/viewer/2022051816/5444da80b1af9f4f6c8b459c/html5/thumbnails/66.jpg)
Thank you!