Sending RequestContext to remote Actors

We have built lots of code around using Akka-Http within a single node. I’m trying to see if I can scale it out by using Akka-Cluster and send the Http requests to a remote worker Actor. I know that it is probably better to perform all Akka-Http stuff locally and then send the payload to a remote worker Actor. Unfortunately, it would be way easier if I can send the whole RequestContext and get back a Route. I cannot serialize it fully:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: ClusteredApiProcessor$RequestContextCommand["requestContext"]->akka.http.scaladsl.server.RequestContextImpl["request"]->akka.http.scaladsl.model.HttpRequest["entity"]->akka.http.scaladsl.model.HttpEntity$Strict["dataBytes"]->akka.stream.javadsl.Source["delegate"]->akka.stream.scaladsl.Source["traversalBuilder"]->akka.stream.impl.LinearTraversalBuilder["outPort"]->akka.stream.Outlet["mappedTo"])

I’m guessing the entity Stream is not friendly towards this? Is there a way to a) extractEntityLocally and then send RequestContext mapping in a null for the entityStream? Anyone else attempted something similar to marry Akka-Http with Akka-Cluster?

Thanks much

The RequestContext contains references to the request stream and the materializer so that will not be possible to serialize and send across the wire.

I’d recommend that you keep the HTTP server logic local (think of it as the border of your application) and have specific protocols for your workers (potentially using StreamRefs if you need to stream data between nodes).

I agree with @johanandren. In the end, to send a message between hosts, you need some serialization format. Akka Http’s message model already is a model of the serialization format that is HTTP, so it would be a bit weird to wrap those with another layer of serialization. So, the natural way would be to have an HTTP server on each node and send those HTTP messages around as real HTTP requests.