Akka Memory: Durable, in-memory, and sharded data

10 minute read

Introduction

Akka Memory provides durable, in-memory, and sharded data for AI agents. It gives agents the ability to recall and reason across both short-term and long-term sessions, supporting fast, low-latency decisions and maintaining continuity across sessions, users, and goals.

This kind of memory is essential for context engineering: structuring and optimizing what an agent knows so it can perform complex tasks reliably across multiple interactions. With Akka Memory, your agents can stay coherent, personalized, and informed.

Durable event-sourced memory

One of the things I love about Akka Memory is its event-sourced backbone. If you're not familiar with event sourcing, it's an architecture pattern that tracks state changes sequentially as a series of events and persists those events transparently to an event journal.

Think of it like an audit log. Every time something transpires, we record it as an immutable historical event. For optimization purposes, we also provide snapshotting to capture the current state of an Agent or Entity. Then, upon startup, we don't have to replay all the events to construct the current state, we only need to fetch the last good snapshot and replay the subsequent events. The great thing is it automatically captures all state changes, not just conversations. If an agent calls an API (i.e., not the LLM) that is part of the memory!

empty-recovered-state-agent

The image above captures the essence of Durable event-sourced memory. (1) The app starts with its state empty. (2) Upon instantiation, the app requests from the event store to replay all the historical events. (3) On the right we see the app fully hydrated.

Subscribe to memory (event) changes

Another great feature in Akka Memory is how naturally it handles real-time change. Whenever a piece of information is updated, Akka's event-driven memory tracks it as an immutable fact and instantly streams those changes to any interested agents or components. With Akka Streaming, setting up these subscriptions feels intuitive, you "tune in" to memory events, and your agents become immediately aware of what's happening, without the need for messy polling or manual checks.

This feature of Akka Memory isn't just a technical convenience; it forms the foundation for adaptive systems. Agents can respond, coordinate, and update their behavior the moment something shifts in their environment. You can even combine streams from different memories using Views, shaping the information flow to fit precisely what your application needs. For anyone building real-time, agentic AI, this subscription model unlocks a whole new level of flexibility and situational awareness.

subscribe-memory-alt

In this image we see events are emitted for consumption on the right.

Using Events for Evaluation

Evaluation events give your agents a built-in feedback loop by emitting state-change notifications that other agents can consume and act on in real time. For example, the PreferencesEntity will emit an event whenever user preferences are updated. You can hook an EvaluatorAgent to that event stream via a Consumer so it automatically rates the quality of prior suggestions and decides if new ones are needed in real-time. In addition, events can be replayed offline, which is essential for improving and tuning core agent performance.

I’ve found this “LLM as judge” pattern invaluable for enforcing business rules and maintaining high response quality without polling or manual triggers, your agents simply listen for events, evaluate and adjust their behavior on the fly.

@ComponentId("evaluator-agent")
@AgentDescription(
  name = "Evaluator Agent",
  description = """
  An agent that acts as an LLM judge to evaluate the quality of 
  AI responses.
  It assesses whether the final answer is appropriate for the 
  original question and checks for any deviations from user
  preferences.
  """,
  role = "worker"
)
public class EvaluatorAgent extends Agent {

  public record EvaluationRequest(
    String userId,
    String originalRequest,
    String finalAnswer
  ) {}
...

The code snippet above is what an evaluator agent might look like.

Sharded and in-memory data for superfast write and reads

Akka Memory leverages the SDK's stateful components—Agents (session memory), Event-sourced entities, Key-value entities, and Workflows, which automatically distribute across your cluster via cluster sharding. Each component instance is bound to a single shard, and those shards rebalance transparently as nodes join or leave, preventing hotspots and delivering elastic performance. While an agent, entity, or workflow is active, its state resides in the JVM heap, allowing reads to access memory directly for sub-millisecond latency and writes to update asynchronously to the journal.

When instances become idle or memory pressure builds, Akka passivates the least-recently used components, snapshotting or offloading their state to durable storage, freeing heap space without requiring any extra code. For geo-scale resilience, every write in the primary region is propagated asynchronously to the read-replica areas, enabling local low-latency reads while ensuring eventual consistency across your multi-region deployment.

Data sharding

App data is partitioned across in-memory, durable nodes. Akka routes user requests to the correct instance.

sharded-data

Data rebalancing

Data shards are re-balanced as the
number of runtime nodes changes.

data-rebalancing-1

The images above represent sharded data and data rebalancing.

Tracing and auditability

Tracing and auditability are non-negotiables in agentic AI, and Akka Memory addresses them thoroughly. Every memory interaction, user inputs, tool calls, and LLM exchanges, are recorded as immutable events in a replayable stream, with workflows logging each transition and call stack.

This level of traceability accelerates incident response and root-cause analysis across agentic systems. All events are persisted in an encrypted, tamper-evident journal, ensuring immutability and non-repudiation for audit and compliance. You can define retention policies to meet governance requirements or subscribe to change events to trigger real-time alerts, automated compliance workflows, and security checks.

memory-event-journal-alt

The image above shows the progression of stored events. In this case we start at the bottom and move up, and we can see Mary Poppins is getting younger!

Transparent memory

With Akka Memory, you don't spend hours wiring up state stores or persistence layers; memory "shows up" for agents, workflows, and streams out of the box. Developers can quickly spin up an agentic service and immediately have a working memory layer underneath, without writing a single line of boilerplate code. Behind the scenes, Akka transparently handles in-memory caching, sharding, and durable persistence.

On top of that, you're not limited to the built-in memory types. If you need custom, shared memory objects, say, to maintain cross-session counters, shared preferences, or global configuration, you can define them once and have them injected into your agent.

public Effect<String> ask(String question) {
  return effects()
    .memory(MemoryProvider.custom())
    .systemMessage("You are a helpful...")
    .userMessage(question)
    .thenReply();
}

MemoryProvider.custom() - Allows you to provide a custom implementation for the SessionMemory interface and store the session memory externally in a database / service of your preference.

Short-term and long-term memory

Short-term memory

With Akka Memory, short-term memory comes built into the Agent component as transparent, traced “session memory.” By default, every user message, agent decision, and tool invocation is recorded in sequence and persisted as an event-sourced entity tied to a session ID; no extra code required.

This invisible memory layer gives your agents immediate situational awareness: they can pull in the last few interactions on demand, reason over that recent history with micro-latency, and keep conversations or workflows coherent and contextually relevant throughout a session.

Long-term memory

With Akka Memory, long-term memory is powered by stateful components, such as workflows, event-sourced entities, and key-value entities, that enable the persistence of semantic knowledge, skills, and retrieved data across users, sessions, agents, and systems.

Akka’s Event-sourced entities are designed for both durability and speed: thanks to snapshotting, the system captures point-in-time state so that recovery or loading starts from the last snapshot and only replays recent events, keeping startup fast and subsequent reads served directly from memory with microsecond-level latency. Key-value Entities complement this by persisting only the latest state on each update, giving you instant, low-latency access without any event-stream processing. Together, they deliver a resilient, high-performance long-term memory layer.

Compaction

I've found compaction invaluable for keeping session histories manageable as they grow. With Akka Memory, you can invoke a CompactionAgent to summarize past interactions via an LLM, replacing verbose event streams with concise, context-rich snapshots, without losing any critical information. This auto-summarization can be triggered whenever a history size threshold is exceeded, ensuring your agents stay performant and your storage stays lean. Plus, because it leverages the same event-sourced infrastructure, you still get full replayability and audit trails even after compaction.

Views

Akka Memory provides a component called a view, which enables you to build read-optimized projections of state by consuming events and updates from across your system, without modifying the original entities or workflows. Think of a View as a continuously maintained, queryable snapshot that pulls together the precise data you need for dashboards, analytics, or inter-service coordination. By decoupling reads from writes, Views enable high-performance, denormalized access patterns while keeping your core components clean and focused.

  • Event sourced entity events: Project immutable event streams into custom tables or materialized views to support complex audit or analytics queries
  • Key value entity state: Consume change notifications from key-value stores to reflect the latest state in low-latency read models
  • Workflow transitions: Subscribe to workflow state changes to monitor long-running processes and derive operational metrics
  • Broker topics & service events: Integrate external or cross-service messages (e.g., Kafka, Pub/Sub, or Akka service-to-service events) into your views for unified insights and real-time dashboards

Conclusion

The Akka Agentic Platform

Akka, Memory is a core part of our agentic AI platform. Alongside Akka Agents, Akka Orchestration, and Akka Streaming, it delivers instant recall and lasting insights to keep your systems coherent and resilient, whether you’re running adaptive workflows, conversational assistants, or data pipelines.

By decoupling state from behavior, Akka Memory provides transparent session tracking and enterprise-grade persistence. Your agents get instant context, effortlessly persist long-term knowledge, and tap into real-time event streams for adaptive decisions—all with cloud-native scalability and fault tolerance.

akka-agentic-platform-alt

For more information see our docs.

Final thoughts

I’ve found Akka Memory’s mix of instant session recall and durable persistence to be a game-changer. Session memory hooks directly into agents for micro-latency context, while Event-sourced and Key-value entities journal every change for full replayability and audit trails. Cluster sharding and geo-replication then transparently distribute and safeguard that state, and Views plus evaluation-event streams let me build read-optimized projections and real-time feedback loops with minimal code. Add automatic compaction and tamper-evident logs, no extra setup required, and you have a battle-tested, enterprise-grade foundation for building scalable, resilient agentic AI.

Ready to unlock reliable, maintainable agentic AI systems? Give the Akka SDK a try in your next AI service, and experience how they simplify complex AI patterns into reusable, composable building blocks.

When AI Needs an SLA