Design: Event Sourcing System
Design the event sourcing pattern implementation within a microservices architecture including event storage, event publishing, state rebuilding, and querying. Out of scope: UI design, specific business logic details.
Functional Requirements
FR1: Store all changes to application state as a sequence of events.
FR2: Allow rebuilding current state by replaying events.
FR3: Support querying current state efficiently.
FR4: Ensure events are immutable and append-only.
FR5: Support multiple microservices consuming events asynchronously.
FR6: Provide audit trail for all changes.
FR7: Handle concurrent updates safely.
Non-Functional Requirements
NFR1: System must handle 10,000 events per second.
NFR2: Event replay latency should be under 5 seconds for rebuilding state.
NFR3: Availability target of 99.9% uptime.
NFR4: Event storage must be durable and scalable.
NFR5: APIs should respond within 200ms p99 latency.