Overview

Event-sourced apps store data as a sequence of events rather than just the current state. This approach records all changes to an application's state, creating a complete history of actions and modifications. Event sourcing enables comprehensive audit trails, system state reconstruction, and alternative data views. This design pattern is particularly useful in complex systems where tracking changes and maintaining data consistency are critical.

akka-edge-apps
AI apps architecture

lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum

What is an event sourced app?

Event-sourced apps capture all changes to the application state as a sequence of events. These events are stored in order, forming an event log. The current state of the application can be derived by replaying these events from the beginning.

Event sourcing is particularly well-suited for distributed service systems. It provides a natural way to maintain consistency across multiple services, as each can subscribe to and process relevant events. This approach facilitates loose coupling between services, enhances elasticity, and supports eventual consistency in distributed environments.

Key properties of event-sourced apps

Event-sourced apps possess several distinctive characteristics that shape their behavior and capabilities.

Immutable event log
All state changes are recorded as immutable events. Once an event is stored, it is never modified or deleted.
State reconstruction
The current state is recreated by replaying all events from the beginning, allowing for point-in-time reconstruction of past states.
Audit trail
The event log provides a complete history of all changes. This built-in audit capability is useful for debugging and compliance purposes.
Temporal query capability
The system can answer questions about its state at any point in its history. This enables time-travel queries and historical analysis.
Event-driven architecture
Event-sourced apps naturally fit into event-driven architectures. Services can react to events, enabling loose coupling and scalability.
Multiple projections
The same event data can be used to create different read models or projections optimized for specific use cases or query patterns.
Separation of concerns
Event-sourced apps implement Command Query Responsibility Segregation (CQRS), distinctly separating the processing of commands (write operations) from the handling of queries (read operations).
Integrations, analysis, and AI & ML
Event-sourced apps facilitate powerful integrations and analytics. The event stream enables seamless external system integration and provides comprehensive data for analysis. The chronological log offers a rich dataset for AI/ML models, supporting predictive modeling and anomaly detection based on historical patterns.

Akka components

  1. A client sends a request to the endpoint.
  2. The endpoint forwards the request to the view and then sends a command to the entity.
  3. The entity processes the request, updates the state, and emits events in an event log.
  4. A consumer component distributes events to other components or services.
akka-event-sourced-apps-2

How Akka enables event sourced apps

Akka simplifies building scalable, resilient, event-sourced applications in distributed systems. It provides efficient event handling, storage, and processing while maintaining consistency and fault tolerance. This approach facilitates the creation of adaptable, complex, event-driven systems that can handle varying loads and recover from failures.

Event-sourced entities
The event-sourced entity in Akka processes incoming commands emits events, and applies these events to change the entity's state. This ensures that every state change is tracked as an event, making the system auditable and allowing for complete state reconstruction.
CQRS views
View components in Akka subscribe to event-sourced entity event streams, consuming the events and transforming them into queryable view tables. This implementation follows the Command Query Responsibility Segregation (CQRS) pattern, clearly separating command handling (write operations) from query handling (read operations).
Event streaming
Akka provides streaming components that consume events from event-sourced entities and forward them to other entity components. This communication happens with reliable, at-least-once message delivery guarantees, ensuring no events are missed during streaming, which is critical for maintaining consistency in distributed systems.
Scalable clusters
Akka's cluster sharding feature distributes data and computing workloads across scalable, distributed clusters. This allows event-sourced entities, views, and streaming components to scale effectively by balancing the load across the cluster, ensuring resilience and performance even under heavy workloads.
Edge, local, cloud, multi-region
Akka supports edge-to-multi-region cloud deployments with active-active replication, brokerless messaging for edge-cloud sync, and location transparency. Cluster sharding and distributed data enable scalable, fault-tolerant systems.

Related case studies

reflek-logo-white

Reflek.io’s digital twins deliver millions in annual savings for Renault

verizon-logo-white

Verizon saw a 235% increase in sales after switching to Akka

ramen-logo-white

Ramen's NaaS delivers SLA-backed connectivity to thousands of IoT devices

Related content

QA - Akka 3 frequently asked questions

InfoQ webinar: the architect's guide to elasticity

Lightbend and Scalac partner to enable enterprises to leverage the power of Akka

Akka license keys and a no SPAM promise

O’Reilly webinar: transcending the barriers to elasticity

Akka innovations: multi-cloud, edge, and security enhancements

Benchmarking database sharding in Akka

Not all CVE fixes are created equal

Stay Responsive
to Change.