Messaging Patterns
Event Sourcing: Storing State as a Sequence of Events
Instead of persisting current state, store every change as an immutable event and derive state by replaying the log.
In event sourcing, the database is an append-only event log. Current state is a left-fold over all events for an aggregate. This gives you a complete audit trail, the ability to replay history for debugging, and a natural integration bus — other services subscribe to the same event stream. The trade-off is query complexity: you must build and maintain read-model projections.
{ "type": "OrderPlaced", "orderId": "ord-1", "total": 49.99 }
{ "type": "ItemAdded", "orderId": "ord-1", "sku": "ABC", "qty": 2 }
{ "type": "OrderShipped", "orderId": "ord-1", "trackingId": "TRK-99" }Continue reading
- →
Dependency Injection and IoC Containers
Invert control of dependency creation to keep classes decoupled from their collaborators and trivially testable.
- →
The Observer Pattern and Event-Driven Design
Decouple publishers from subscribers by letting objects register interest in events without the producer knowing who is listening.
- →
The Strategy Pattern: Encapsulating Algorithms
Define a family of algorithms, encapsulate each one, and make them interchangeable — open for extension, closed for modification.