akka/akka-core

Serialization issues with Option

Open

#29,923 opened on Dec 30, 2020

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Scala (3,547 forks)batch import
1 - triagedhelp wanted

Repository metrics

Stars
 (13,277 stars)
PR merge metrics
 (Avg merge 8d 19h) (10 merged PRs in 30d)

Description

Some example projects and also the current style guide recommend using Option for state in event sourced behaviors (entities). This causes two issues:

  1. Double serialization - Option is caught by MiscMessageSerializer, which delegates payload serialization to another serializer based on configuration and then serializes the result again with ContainerFormats.Option.
  2. Payload serialization is always synchronous, so this results in blocking IO in a case where state uses AsyncSerializer.

These issues could be fixed by implementing following changes:

  1. Altering documentation to suggest using sealed trait hierarchies or case classes which contain Option to express empty state.
  2. Converting MiscMessageSerializer to AsyncSerializer.

Behavior seems obviously undesirable, so I'm wondering if I am missing something or does this actually need fixing?

I've noticed this issue with Lagom 1.6.4 entities, but since they fallback to Akka actors for everything I assume this is a general Akka issue.

Contributor guide