Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

636
Views
Real-time update on Django application using MySQL <> WebSocket

I need to continuously get data from a MySQL database which gets data with an update frequency of around 200 ms. I need to continuously update the data value on the dashboard text field.My dashboard is built on Django.

I have read a lot about Channels but all the tutorials are about chat applications. I know that I need to implement WebSockets which will basically have an open connection and get the data. With the chat application, it makes sense but I haven't come across anything which talks about MySQL database.

I also read about mysql-events. Since the data which is getting in the table is from an external sensor, I don't understand how I can monitor a table inside Django i.e whenever a new row is added in the table, I need to get that new inserted based on a column value.

Any ideas on how to go about it? I have gone through a lot of articles and I couldnt find something specific to this requirement.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Build a microservice for Websockets connections

Another way to implement such a feature - is to build a standalone WebSocket microservice.

Monolyth architecture isn't what you need here. Every WebSocket will open a connection to the Django (which will be behind reverse proxy and server: NGINX and Gunicorn ex.). If your client opens two tabs in the browser you will get 2 connections etc...

My recommendation is to modify the tech stack (yes, I'm a huge fan of Django, but there are many cool solutions in building WS):

  1. Use Starlette ready for production framework with build-in WebSockets: https://www.starlette.io/websockets/
  2. Use uvicorn.workers.UvicornWorker for Gunicorn to manage your ASGI application: this is only 1 line of code, like gunicorn -w 4 -k uvicorn.workers.UvicornWorker --log-level warning example:app
  3. handle your WebSocket connections and use examples to request updates from the database: https://www.starlette.io/database/
  4. Use super simple Javascript code to open the connection of the client-side and listen for updates.

So your models, templates, the view will be managed by Django. Your WebSocket connections will be managed by Starlette in a native async way. If you're interested in such an option I can make detailed instructions.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!