Finance's Forgotten Treasure: an Introduction to CQRS & Axon

  • 262 views
Uploaded on

Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1vALlg7. …

Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1vALlg7.

Allard Buijze introduces CQRS and related concepts along with case studies showing how it is used in finance, gaming and healthcare to meet the demands of modern web-based applications. Filmed at qconlondon.com.

Allard Buijze is software architect at Trifork Amsterdam, which delivers software development, consultancy and training services to both national and international organizations. As an architect, he is responsible for the technical choices in his projects and investigates technologies for their potential in the diversity of projects Trifork does.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
262
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. An introduction to CQRS and Axon Framework Finance’s ‘forgotten’ treasure Allard Buijze – allard.buijze@trifork.nl
  • 2. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations /cqrs-axon InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month
  • 3. Presented at QCon London www.qconlondon.com Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide
  • 4. Allard Buijze ! Software Architect at Trifork Amsterdam ! ~ 15 years of web development experience ! Strong believer in DDD and CQRS ! Developer and initiator of Axon Framework ! Java Framework for scalability and performance ! www.axonframework.org
  • 5. Layered architecture
  • 6. Evolution of a Domain Model
  • 7. Evolution of a Domain Model
  • 8. Evolution of a Domain Model
  • 9. Evolution of complexity Source: h*p://royal.pingdom.com/2008/01/09/the-­‐worst-­‐cable-­‐mess-­‐ever/
  • 10. Evolution of complexity private static final String PLAYER_COCKPIT_WATERFALL_ITEMS_QUERY = "(" + "select id, " + EntityType.NEWS_ITEM.ordinal() + " as entity_type, publish_date as sort_date " + "from news_item " + "where active = true and (" + NEWS_ITEM SELECT "poster_player_id = :playerId " + "or poster_player_id in (" + or "select destination_project friend_id from in friendship (… where origin_friend_id = :playerId " + ") " + "or project_id in (" + "select distinct project_id " + or "from donation project " + in (… "where donor_participant_id = :playerId and status = 'OK'" + ")" + "or project_id in (" + "select project_id from ambassador_project where player_id = :playerId " + "))" + UNION ALL DONATION status = ‘OK’ status = ‘OK’ ") union all (" + "select id, " + EntityType.DONATION.ordinal() + " as entity_type, approval_date as sort_date " + "from donation " + "where status = 'OK' and (" + "donor_participant_id = :playerId " + "or donor_participant_id in (" + "select destination_friend_id from friendship where origin_friend_id = :playerId" + ")" + "or raised_via_player_id = :playerId " + "or raised_via_player_id in (" + "select destination_friend_id from friendship where origin_friend_id = :playerId" + ") " + ") " + or raised_via_player in (… UNION ALL FRIENDSHIP ") union all ( " + "select id, " + EntityType.FRIENDSHIP.ordinal() + " as entity_type, created as sort_date " + "from friendship " + "where origin_friend_id = :playerId or (origin_friend_id in ( " + "select destination_friend_id from friendship where origin_friend_id = :playerId " + ") and destination_friend_id <> :playerId)" + ") ";
  • 11. Layered architecture Web Cache Session replicaYon Method invocaYon Cache Worker pools Distributed 2nd level cache Query Cache
  • 12. Designed for high performance (?)
  • 13. Then vs Now 1970’s 2014
  • 14. Brought to us by the Financial Sector Sources (ltr *b): guides.wikinut.com (2x), telegraph.co.uk, commons.wikimedia.org, usatoday.com
  • 15. Brought to us by the Financial Sector CQRS (LMAX) Disruptor mechaniYs.blogspot.com Source:
  • 16. CQRS Based Architecture
  • 17. CQRS Based Architecture Command model ProjecYons
  • 18. CQRS Based Architecture Command model ProjecYons
  • 19. CQRS Based Architecture Command model ProjecYons T: 1 mln / s Resp: < 10 ms T: Thr. 20 / s Resp: < 100 ms T: 10 mln / s Resp. < 100 ms T: 1 / s Resp. < 10 ms
  • 20. Synchronizing models Command model ProjecYons StoredE vperonctse dures
  • 21. CQRS Based Architecture
  • 22. The power of ubiquitous events Polling ReacYve Cache evicYon Push Real-­‐Yme Event Sourcing LocaYon transparency Systems integraYon
  • 23. Event Sourcing
  • 24. Event Sourcing OrderItems ID OrderID Product Count 1 1 Deluxe Chair 1 2 1 ... ... vs Orders ID Status 1 Return shipment rcvd Seq# Event 0 OrderCreatedEvent 1 ItemAddedEvent (2x Deluxe Chair -­‐ € 399) 2 ItemRemovedEvent (1x Deluxe Chair -­‐ € 399) 3 OrderConfirmed 4 OrderCancelledByUserEvent 5 ReturnShipmentReceived
  • 25. Event Sourcing ! Pros ! Audit trail ! Reconstruct query model(s) ! Management reports since day 1 ! Data analysis ! Cons ! Maintain history (upcasters) ! Ever-growing
  • 26. Axon Framework ! “CQRS Framework” for Java ! Open source under Apache 2 License ! Simplify CQRS based applications ! Provides building blocks for CQRS applications ! Current version*: 2.1 ! More information: www.AxonFramework.org * On January 9th, 2014
  • 27. CQRS Based Architecture
  • 28. Axon – Command Bus API commandBus.dispatch(commandMessage, new VoidCallback() { @Override public void onSuccess() { ... } @Override public void onFailure(Throwable cause) { ... } }); @CommandHandler public void handle(CreateToDoItemCommand command) { // handle command }
  • 29. Axon – Event Bus API eventBus.publish(asEventMessage(new ToDoItemCompletedEvent(“todo1”))); @EventHandler public void onEvent(ToDoItemCompletedEvent event) { // handle event }
  • 30. CQRS Based Architecture interface AggregateRoot abstract class AbstractAggregateRoot interface EventSourcedAggregateRoot abstract class AbstractAnnotatedAggregateRoot
  • 31. Axon – Event Sourcing Apply state Make decisions
  • 32. Event Sourcing - Testing ! Given-when-then fixtures ! Given some past events ! When I apply a new Command ! Expect these new Events fixture.given(new GameStartedEvent(…), new CallMadeEvent(…), new TurnChangedEvent(…)) .when(new MakeCallCommand(…)) .expectEvents(new CallMadeEvent(…), new TurnChangedEvent(…));
  • 33. Separate infrastructure from business logic A D B E C
  • 34. Separate infrastructure from business logic A D B E C
  • 35. Separate infrastructure from business logic A D B E C
  • 36. Spring configuration - Simple
  • 37. Spring configuration – High performance
  • 38. Spring configuration – Distributed Events
  • 39. Spring configuration – Distributed Commands
  • 40. Infrastructure components in Axon ! Single VM ! SimpleCommandBus ! SimpleEventBus ! High Performance ! DisruptorCommandBus ! ... ! Distributed ! DistributedCommandBus + JGroupsConnector ! ClusteringEventBus + AMQP Terminal ! ...
  • 41. Axon Roadmap ! More distributed implementations ! Improved OSGi support ! DSL for definition of Command & Events ! IDE Plugins ! High performance Event Store
  • 42. Axon Framework – Some cases ! Finance ! Process automation in a top 50 bank ! Trading engine for ETF (index trackers) trading ! Pension fund calculations at a large bank ! On-line payment processing ! Gaming ! On-line bridge platform (bridgebig.com) ! On-line casino (casumo.com) ! Healthcare ! Electronic Medical Record for the Geriatric Healthcare ! Tracking and Tracing of equipment for dental implants ! Aviation ! Optimizing aircraft movement at a large European airport
  • 43. The next time…
  • 44. More information: axonframework.org Allard Buijze abu@trifork.com
  • 45. Watch the video with slide synchronization on InfoQ.com! http://www.infoq.com/presentations/cqrs-axon