PostgreSQL JSON

By default, the serialized event, snapshot and durable state payloads, are stored in BYTEA columns. Alternatively, you can use JSONB column type to take advantage of PostgreSQL support for JSON Types. For example, then you can add secondary jsonb indexes on the payload content for queries.

To enable JSONB payloads you need the following.

  1. Create the schema as shown in the Postgres JSONB tab in Creating the schema.

  2. Define configuration:

    akka.persistence.r2dbc {
      journal.payload-column-type = JSONB
      snapshot.payload-column-type = JSONB
      state.payload-column-type = JSONB
    }
    
  3. Serialize the event, snapshot and durable state payloads as JSON bytes.

For the serialization you can use:

  • Akka Serialization with Jackson with JSON format.
  • Make sure to disable compression with akka.serialization.jackson.jackson-json.compression.algorithm = off
  • Plain strings in JSON format.
  • A custom Akka serializer that uses a binary format as UTF-8 encoded JSON string.

Note that you can enable this feature selectively for the event journal, snapshot, and durable state.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.