0

I need some advice or help, I am trying to create an ordering system like the one in McDonald's and I need a live feed of the current orders and being able to manipulate these in real time as well, however I am not sure how to do that other than sending a get request like every second however that can cause performance problems, is there any other way?

1 Answers1

2

There is! It's called socket.io and is made for real-time communication. In most cases, you have a server which manages the communication and also has a database. All clients will connect to this server and emit data or subscribe to events.

There are tons of tutorials out there. I recommend you to follow one and build a simple chat application, before you use it in your ordering application.

Manuel
  • 188
  • 1
  • 12
  • I have built a chat app with socket.io however I'm not sure how that links to realtime data being given? – James Westhead Jun 28 '21 at 11:47
  • Instead of making a request each second, the live feed can subscribe to the websocket (which is running on the server). If a customer makes an order, the server will take care of the order and emit a event to the client. Then, re-render your components and voilà. – Manuel Jun 28 '21 at 11:51
  • Oh right, and if there was an update to the database, do the same as that? – James Westhead Jun 28 '21 at 14:04
  • Yes! But you might not be able to subscribe to database events, depending on your backend & framework. Ideally, you emit events in your endpoints. [GraphQL](https://graphql.org/blog/subscriptions-in-graphql-and-relay/) seems to support such subscribtions, but i never used them. – Manuel Jun 28 '21 at 14:31