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
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.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String