Should I Use WebSockets Alongside REST for Notifications?

0
3
Asked By TechieNinja42 On

I'm transitioning to backend development and currently building an API with Python (Flask) for a project that handles most of our site's traffic. We've encountered a situation where we need various types of notifications in the app. I thought of using WebSockets, but I'm not experienced with them. I'm considering the Flask-SocketIO library to create separate channels for each user to receive notifications. However, I have concerns about whether this is the right approach, especially regarding performance and concurrency. Can REST and WebSockets coexist in the same service, and how would that impact performance? Is it better to separate them into different services—one for WebSockets and another for API calls?

3 Answers

Answered By TechieNinja42 On
Answered By DevGuru99 On

WebSockets are great for scenarios where you need real-time communication, like sending notifications from the server to clients without them having to request it. But yeah, they introduce some complexity because they make your application stateful, which is different from the traditional stateless nature of HTTP. If your app just needs occasional updates and the timing isn’t super critical, polling could still work fine. But if you go with WebSockets, keep them limited to just notification delivery. You can implement identity tokens to track who’s connected, and use WebSockets specifically for notifications while relying on REST for other API interactions.

Answered By CodeCrafter77 On

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.