I need to have real time updates from one Rails app to another.
One Rails app of mine runs in a restaurant, in a local environment, but is connected to the internet.
Another Rails app is a public web app hosted in DigitalOcean.
When an order is received in the public server, regarding a specific restaurant, for example "Restaurant X", I want to push data, for example "1 tortilla and 1 pepsi" to Restaurant X's local server. And vice versa. An order received in Restaurant X should be immediately published to the public server.
The way I currently implement this, is by having every restaurant (Restaurant X, Restaurant Y and Restaurant Z) polling the public server every 20 seconds, but I wanted to publish changes automatically.
Rails has a Channels functionality to aid in real-time updates, but the examples are only based on Rails app publishing to Javascript-based clients. I wanted the restaurants's servers to be the clients. Meaning, a Rails app publishing to clients that are another Rails apps, 1 room per restaurant. How could I accomplish that, please?
Instead of polling, you're looking for the pub/sub design pattern. Here's a nice tutorial: https://www.toptal.com/ruby-on-rails/the-publish-subscribe-pattern-on-rails