What is the best way to connect Phoenix app with Scala/Akka?

I’m re-architecting an existing Scala/Akka app to use Phoenix app as main API endpoint and to manage most of the data. Remaining Scala part contains some business logic, that needs access to data that’s stored in Postgres (managed by Phoenix), and should respond to some API calls. I wonder, what’s the best way to connect Scala app to Phoenix and vice versa?

I don’t want to access Postgres directly from Scala, since there’s quite a lot of logic involved in figuring out what data is accessible to who. One obvious approach is to just use Phoenix API from Scala via HTTP library, but maybe there’s some alternatives to that?

It’s also possible to expose API on Scala app, and make reverse proxy with Phoenix. But maybe there’s some alternatives to that as well?

1 Like

Without the details I can’t be sure but Jinterface could be worth looking into. Another option could be to use RabbitMQ (or something like it; tutorial) - but only if it would actually simplify matters; throwing “yet something else” in could exacerbate an already complicated situation.\

PS: What would concern me a bit is that a request coming into Phoenix gets forwarded to Akka/Scala which then turns around to request something from Postgres through Elixir (Ecto?). I’d expect to have to pay particular attention to any potential additional data marshalling overhead, complexity and lag.

Thanks, I’ll check JInterface out.

I was thinking about linearizing this flow with Phoenix fetching the data needed for Akka app, and then sending it together with original request. This may save a round trip and reduce latency. Another option, of course, is to cache this data on Akka side.

What did you end up using?

RabbitMQ :slight_smile: It worked well enough for my case. Just using standard RPC pattern with it, providing server and client implementations on both sides.

1 Like