Designing Event-Driven Architecture

1. Understanding Event-Driven Architecture Patterns

PatternDescription
Event NotificationLightweight signal; consumer fetches details
Event-Carried State TransferEvent includes full payload
Event SourcingEvents are source of truth
CQRSCommands write events; queries read projections

2. Designing Event Producers and Consumers

SideConcern
ProducerAtomicity (outbox), idempotent send, schema
ConsumerIdempotent processing, offset commit after success
GroupPartition assignment, rebalance handling
BackpressurePause consumer if downstream slow

3. Designing Event Schema Design

FieldPurpose
event_idUnique (UUID); for dedup
event_typeOrderPlaced, OrderShipped
event_versionSchema version
occurred_atISO timestamp
aggregate_idEntity id
dataPayload
metadataTrace, user, tenant

4. Designing Event Schema Registry

ToolNotes
Confluent Schema RegistryAvro/JSON/Protobuf compatibility
AWS Glue Schema RegistryNative AWS
Compatibility modesBACKWARD, FORWARD, FULL, NONE
Subject namingtopic-value, topic-key

5. Designing Event Versioning Strategy

StrategyDetail
AdditiveAdd optional fields; safe
UpcastingTransform old → new on read
Multiple typesOrderPlacedV1, OrderPlacedV2
Topic-per-versionorders.v1, orders.v2

6. Designing Event Sourcing Pattern

ElementDetail
Event storeAppend-only (EventStoreDB, Kafka, DB table)
AggregateRehydrated by replay
SnapshotCache current state every N events
ProjectionsRead models built from events
ProsAudit, replay, time travel
ConsSchema migration, eventual consistency

7. Designing Event Replay Capability

Use CaseDetail
New projectionReplay all events into new read model
Bug fix backfillReprocess from offset 0
A/B logicReplay into shadow consumer
ToolsKafka offset reset, Kinesis replay

8. Designing Event Ordering Guarantees

ScopeDetail
Per partitionKafka guarantees order
Per keyPartition by aggregate_id
GlobalSingle partition (low throughput)
Reordering safeUse sequence number / version

9. Designing Event Deduplication

StrategyDetail
Idempotent producerKafka enable.idempotence=true
Inbox patternConsumer DB stores processed event_id
TTL bloom filterMemory-efficient dedup window
Broker-sidePulsar deduplication

10. Designing Event-Carried State Transfer

ProCon
Consumer self-sufficient (no callback)Larger events
Resilient to producer outageStale data if consumer slow
Easy to materialize read modelPII/sensitive data spread

11. Designing Choreography vs Orchestration

AspectChoreographyOrchestration
ControlDistributed; services reactCentral orchestrator
CouplingLooseCoupled to orchestrator
ObservabilityHard (multi-hop)Easy (one place)
Best forSimple flows, evolvingComplex / regulated workflows
ToolsKafka eventsTemporal, Camunda, Step Functions

12. Designing Event Store Architecture

ImplementationDetail
Append-only table(stream_id, version, type, data, metadata, ts)
Optimistic concurrencyAppend fails if version mismatch
SubscriptionTail $all stream; push to consumers
SnapshotsSeparate table; load latest + tail
ToolsEventStoreDB, Marten, Axon, Kafka