A PersistenceId is the unique identity of an event-sourced entity’s stored history. EventSourcedBehavior receives it alongside initial state, command handling, and event handling, so events can be associated with one persistent actor. section 9.2.1
Uniqueness matters especially in a cluster: the same actor ID can otherwise exist on different nodes, and different entity types can reuse the same ID. Combine an EntityTypeKey with the entity ID to distinguish the persistent entity. section 9.2.1 section 9.2.2
A sharded container identity
A container entity can create its behavior with PersistenceId(typeKey.name, containerId). This pairs the container type with its ID before Cluster Sharding initializes and routes the entity. section 9.2.2
Table 9.1 Journal entries in the database table public.journal_events (view table figure)
Journal rows show the resulting persistence_id: containers 9 and 11 have distinct type-key-and-ID values, while sequence numbers track events for each entity. section 9.4
When choosing an identity, keep these operational rules in view:
- Make the persistence ID unique; persistence alone does not check whether a single-node actor ID collides elsewhere in a cluster. section 9.2.1
- Use the entity type key plus entity ID for sharded persistent entities. section 9.2.2
- Expect journal records to store the persistence ID with each event, alongside an entity-specific ascending sequence number. section 9.4
