Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Libs by

We are trying to setup our clojure server to handle websockets but we are using datomic's ion infrastructure on aws, making it not so easy. I wonder if anyone has tried it or has any pointers?

5 Answers

+1 vote
selected by
Best answer

I have not tried this with Datomic Ions, but having researched the possibility of doing this with Google App Engine, I am pretty certain it can't be done (out of the box).

Ions, like App Engine, are 'elastic' systems - they will start/stop nodes as the load varies, and websockets is stateful, i.e. the same server needs to run continuously because it maintains the connection with the websocket client(s).

In theory, Datomic will always have at least 2 nodes constantly running (in production config), so you might argue that they could support a websocket server on one of those nodes, but I think even there you have no guarantee, as a node might fail and get cycled at any time.

I think the way to handle this, is to start your own EC2 instance running the websocket server, and let the clients connect to that. The websocket server can do calls to Ions, but I suspect you want to push some realtime data (else why use websockets), so the way to do this is to have a transaction function that will write info onto a message queue (e.g. Amazon Simple Queue Service), and the websocket server can listen for messages on that queue, and push it to the clients.

Remember to keep the amount of work inside a transaction function to the minimum, otherwise your transaction throughput on Datomic could be severely affected. So:

  • only write the stuff you really need to the message queue, not every single datom being transacted
  • use something like Amazon Simple Queue Service that will scale together with the number of messages you publish. Don't just do calls to your websocket server directly

You can also ask this question on Datomic Forum, they have some good people answering questions there.

I thought I will try and look for the article I read where they explain how to do this on App Engine, and of course, the first link that comes up shows that App Engine is now supporting it (in BETA):

+3 votes

AWS API Gateway support WebSockets via lambdas. So maybe there is a way to set it up with ions. I didn't try it myself yet, but there is hope.

+1 vote

This depends on your use case but if you're only keeping
a page alive with information from the server in real time

You could get away with server sent events and normal http requests
for messaging back to the server

If a server cycles on you, clients will gracefully reconnect to the next box

0 votes

You didn't say what happened...was there a js error? An explosion? Did it start playing toby keith? I haven't connected to an on with a web socket but I've used

I hit submit too early. Might be good to try the datomic forum as well BTW.
0 votes

This is an old thread now, but it's the only one that came up when I searched for Ions + websockets, so I'm posting a link for the benefit of others with this question.

There's a great answer in the Datomic forum:


Welcome to Clojure Q&A, where you can ask questions and receive answers from members of the Clojure community.