Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Evolutionary Microservices with DDD, CQRS and Axon Framework

Evolutionary Microservices with DDD, CQRS and Axon Framework

The rise microservices trend fosters many project teams to deal with a bunch of technologies. Some of the projects starts implementation by putting much effort in the distribution infrastructure.

This talk proposes a different approach. It shows how to use concepts of Domain Driven Design (DDD) combined with Command Query Responsibility Segregation pattern and Event Sourcing (CQRS/ES) and focus on the domain logic first. In doing so, we used Axon Framework for JVM to decouple resulting components and can distribute them after the system construction.

This talk has been presented on Java User Group Hamburg on 28. Jan 2020.

Simon Zambrovski

January 23, 2020
Tweet

Other Decks in Programming

Transcript

  1. Why are we here? ▪ Everyone builds microservices ▪ Many

    start with distribution... ▪ ... and fail ▪ we show how you can do it better
  2. Agenda ▪ Domain Driven Design (DDD) ▪ Implementation Architecture □

    CQRS Pattern □ Event Sourcing ▪ Axon Framework ▪ Demo and Examples ▪ Outline
  3. Why holisticon? ▪ A better company ▪ "New work" for

    10 years ▪ Based in Hamburg and Hannover ▪ 50 engineers ▪ We want you and are still hiring
  4. Domain Driven Design (DDD) ▪ What is it? ▪ Why

    should I know it? ▪ Basic principles
  5. Domain Driven Design ▪ Set of principles, patterns and techniques

    ▪ Analysis □ Domains □ Domain Models ▪ Strategic Design □ Bounded Contexts □ Relationships □ Ubiquitious Language ▪ Tactical Design □ Value Objects, Entities, Aggregates □ Services, Repositories, Factories □ Domain Events ▪ Architecture Design □ Layered □ Hexagonal / Ports and Adapters
  6. DDD: Requirements analysis ▪ Event Storming □ 100.000 stickies from

    Alberto Brandolini □ Collaborative method for strategic and tactical design □ Identifies responsibilities based on events ▪ Domain Storytelling □ Scenarios visualisation from WPS □ Collaborative method to capture domain knowledge □ Identify responsibilities based on activities belonging together □ Can be used as foundation for tactical design ▪ ... or both
  7. DDD: Strategic Design ▪ Identify Domains / Subdomains ▪ Find

    Bounded Contexts (BC) ▪ Identify relationships between BC □ Customer / Supplier □ Conformist □ ... ▪ Ubiquitous Language
  8. DDD: Tactical design ▪ Explore the Bounded Context ▪ Create

    the Domain Model "Domain is about Euros and Customers, not about Decimals and Strings." "Make the incorrect inexpressible!" (Albert Starreveld)
  9. DDD: Tactical Design (Entities) ▪ Value Object □ represents domain

    value ▪ Entity □ has own identity □ values are Value Objects ▪ Aggregate □ object graph from Entities □ guarantees consistency □ aggregate root provides access
  10. DDD: Tactical Design (Services) ▪ Services □ Domain Services □

    Application Services ▪ Repositories ▪ Factories
  11. CQRS: When should I use it? ▪ Asymmetric read/write load

    ▪ Multiple read representations ▪ Eventually consistency is acceptable ▪ Read models will be constructed later
  12. CQRS: Basic Principles ▪ Command (Write) □ used to express

    intent of state change (=mutation) □ has side effects □ has generally no return value ▪ Command handler □ accept / reject commands ▪ Query (Read) □ used to express the query □ has no side effects □ provides typed return ▪ Query handler □ Answers query ▪ Read model (Projection) □ Projection optimized for read □ Serves one purpose
  13. Event Sourcing (ES) ▪ Persistence Strategy for aggregates ▪ Store

    state changes (events), instead of last state ▪ Implicit audit log ▪ Uses Event Store □ Append only store □ May be used for replays □ May support snapshotting
  14. CQRS/ES ▪ Use events to transfer changes from aggregate to

    read model ▪ Use event bus for de-coupling ▪ Store events instead of current state
  15. Axon Framework ▪ What is Axon Framework? ▪ Basic Principes

    ▪ Managed Evolution ▪ Deployment Strategies
  16. What is Axon Framework ▪ Java Framework to construct hexagonal

    architecture and CQRS(/ES) ▪ FOSS ▪ Created by AxonIQ (Netherlands) ▪ Native Spring(boot) support ▪ Can run on Java SE / CDI ▪ Promotes annotations for implementation ▪ Promotes late configuration / evolution
  17. Axon Framework: Basic Principles ▪ Implementing application using three buses

    □ CommandBus □ EventBus □ QueryBus ▪ Implementing Aggregates □ @Aggregate □ @CommandHandler □ @EventSourcingHandler □ Provides aggregate repositories ▪ Implementing Projections (Read Models) □ @EventHandler □ @QueryHandler ▪ Configuration □ Event store □ Token store □ Implementation for buses
  18. Axon Framework: Deployment strategies ▪ Local □ single JVM deployment

    ▪ Distributed with Axon Server □ Axon Server Community □ Axon Server Enterprise □ Axon Cloud ▪ Distributed without Axon Server □ Implement message distribution on your own
  19. Outline ▪ DDD □ helps to understand the problem space

    □ identify the solution space □ design solution architecture ▪ CQRS/ES □ can be applied during implementation □ makes event stream to the ONLY truth ▪ Axon Framework □ Promotes own architecture for CQRS/ES implementation □ Uses buses to de-couple components □ Best-in class framework for JVM □ Promotes late evolution / scaling on demand
  20. Challenges ▪ Same words have different meanings ▪ Strategic design

    matters ▪ Event design is crucial ▪ Event Store is append only