/beam

A microservice used in oorja for realtime messaging between room participants and relaying important events that happen at the backend.

Primary LanguageElixir

Beam

A microservice used in oorja for soft-realtime messaging between room participants and relaying important events that happen at the backend.

This service is written in elixir using the phoenix framework.

Why make a microservice?

  • oorja needed a realtime messaging functionality between room participants. Elixir felt like the perfect tool I could use for this purpose. It's fault tolerant, highly availabile and distributed. You get a lot of stuff for free.
  • Phoenix framework can also track user presence using distributed pubsub.
  • Performance: Initial version of oorja used to watch mongodb oplog for any updates to the Room documents and then used to push the changeset to the room participants. It is how pub/sub works in a meteor app. However cpu usage grows with the number of subscriptions. Now the backend knows when a room document has changed since it is solely responsible for it, so instead of watching the db for changes, the backend now hits Beam to broadcast an event that the room document is updated. Anyone subscribed to the room channel can fetch the updates when they recieve such an event. So in affect pub/sub was removed from the meteor app, bringing down its cpu usage.

Running the app

  • Install Elixir
  • In the project root
    • Install dependencies with mix deps.get
    • Start Phoenix endpoint with mix phx.server

The service should now be running at port 5000.

Learn more