Akka in Action, Second Edition cover
welcome to this free extract from
an online version of the Manning book.
to read more
or

9 Sharding and persistence

 

This chapter covers

  • Distributing actors in a cluster
  • Storing each change of the actor’s state in a database

This chapter discusses two of the seven tools used to build microservices: Akka Sharding and Akka Persistence. The others are Akka Streams, Persistence Query, Projections, HTTP, and gRPC, which you learn about in chapters 10 and 11.

These Akka tools can be used separately (and are traditionally used that way). However, they are increasingly used as a functional unit: looking at them all together helps us better understand them. We call this functional view Akka microservices (to learn more, see appendix B).

Note

The source code for this chapter is available at www.manning.com/books/akka-in-action-second-edition or https://github.com/franciscolo pezsancho/akka-topics/tree/main/chapter09a. You can find the contents of any snippet or listing in the .scala file with the same name as the class, object, or trait.

9.1 Akka sharding and stateful systems

Akka cluster sharding distributes the locations of actors; they are called entities when sharding. With cluster sharding, you can ensure that each entity is unique and that there is at most one in the cluster at any given time.

DEFINITION

Shards are logical containers in which entities are grouped.

9.1.1 The big picture

9.1.2 An example: A shipping container

9.1.3 The simplicity of the sharded entities

9.1.4 Rebalancing configuration

9.1.5 Passivation

9.1.6 Remembering entities

9.2 Persistence

9.2.1 The ingredients

9.2.2 Persistence combined with sharding: A persistent entity

9.2.3 Available effects

sitemap