This document discusses CQRS and event sourcing patterns for Java developers. It begins with an overview of classical monolithic architectures versus modern microservice architectures. It then contrasts CRUD with CQRS, explaining that CQRS separates reads from writes by using commands for writes and queries for reads. Events evolve from commands and represent things that occurred in the past. The document provides an example implementation using the Lagom framework that demonstrates separating the write side from the read side and persisting events. It emphasizes that with this approach, all state changes are stored as events and the current state can be recreated by replaying events. The document encourages the use of Lagom due to benefits like asynchronous programming, developer productivity, and production readiness.
19. • Book-keeping of changes
• Contains a full history implicitly
• Storing events in sequence with a strict global order
(time-stamp based)
• No updates or deletes. Ever!
• No single “current state”. The collection of events
make up the system state in any point of time.
Persistent Events
32. The PersistentEntity
public class CargoEntity extends
PersistentEntity<RegistrationCommand, RegistrationEvent,
CargoState> {
//...
}
CargoEntity.java
51. •Keep all data in memory!
• Store all state changes as events
• Replay all events of an actor to recreate it
• Strong consistencyfor Actor (aggregate) and
Journal
• Eventual Consistencyfor Read Side
https://msdn.microsoft.com/en-us/library/jj554200.aspx
53. Written for architects and developersthat must
quickly gain a fundamental understandingof
microservice-basedarchitectures, this freeO’Reilly
reportexploresthe journey fromSOAto
microservices,discussesapproachesto dismantling
your monolith,and reviews the key tenets ofa
Reactive microservice:
• Isolate all the Things
• Act Autonomously
• Do OneThing, and Do It Well
• Own Your State, Exclusively
• Embrace AsynchronousMessage-Passing
• Stay Mobile,but Addressable
• Collaborate as Systems to Solve Problems
http://bit.ly/ReactiveMicroservice
54. The detailed example inthis reportis based on
Lagom, a new frameworkthat helps you follow the
requirementsfor buildingdistributed,reactive
systems.
• Get an overview of the Reactive Programming
model and basic requirementsfor developing
reactive microservices
• Learnhow to create base services, expose
endpoints,and then connect them with a
simple, web-based user interface
• Understand how to deal with persistence,state,
and clients
• Use integration technologiesto start a
successfulmigration away fromlegacy systems
http://bit.ly/DevelopReactiveMicroservice
55. http://bit.ly/SustainableEnterprise
• Understand thechallenges ofstartinga greenfield
development vs tearingapart an existing brownfield
application into services
• Examine your business domain to see if microservices
would bea good fit
• Explorebest practices for automation,high availability,
data separation,and performance
• Align your development teams around business
capabilities and responsibilities
• Inspect design patterns such as aggregator, proxy,
pipeline, or shared resources to model service
interactions