Is Using Websockets for a Backend-Driven App a Good Idea?

0
7
Asked By CodeCrafter32 On

I'm an experienced programmer, but I'm not deeply familiar with web development. I'm working on an iterative calculation app that gives live progress updates—think of it as a tool similar to ChatGPT but includes some graphical elements as well. My current architecture relies entirely on websockets, where the backend sends requests to the frontend to display updates. The frontend's logic is pretty simple since it only needs to handle these requests and update components accordingly. Is this a valid architecture?

5 Answers

Answered By DesignGuy21 On

We do a mixed approach: we use websockets for live updates (like scores) and REST for stateless operations (like authentication and config). Going websocket-only can complicate debugging and load balancing. If your server handles all calculations, it might work, but I’d keep authentication and configuration on REST for simplicity.

Answered By TechieTommy On

If you're mainly sending data one way, you might want to use Server-Sent Events (SSE). Websockets are best when you need real-time, bidirectional communication, but for what you've described, SSE could do the trick.

Answered By DevDude99 On

Yeah, using websockets definitely works for your app, especially since it needs to show real-time updates for long-running tasks. Just keep in mind what constitutes an "update"; it might draw you into complexities similar to frameworks. Stick with basic state updates in simple JSON so the frontend can easily display the results.

Answered By LogicKing88 On

Your websocket-only design is valid, particularly for real-time updates during calculations. Just remember, it means the backend is the main source of truth for your app’s state, which can lead to more complexity. Also, consider if any calculation logic should be pushed to the client to reduce backend load.

Answered By WebWizard7 On

You're on the right track with websockets, but have you thought about server-sent events? They might be an easier alternative for your setup. They’re great for just pushing updates from the server to the client without the complexity of full websockets.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.