Search code examples
pythondjangodjango-signalsdjango-channels

Django signals vs channels


I have a Django-based project that I would like to make real-time so I thought of Django channels. However, I am still not sure whether this is the right project to apply Django channels and which part of the project I should apply it.

I have a bunch of sensors continuously reading data and saving/updating them into a database in the backend. Data from the database is then passed to the frontend, displayed on a webpage.

Data flow: Sensors > Gateway > Database > Backend > Frontend

I have implemented Django signals to continuously listen to any updates on the database at the backend, in order to perform some notification functions to the user on the frontend.

My Questions

1) In this example, where should I implement Django channels?

  • from sensors to Gateway
  • from gateway to database
  • from database to backend
  • from backend to frontend
  • all of the above

2) Django signals vs Django channels -- overlap?

It feels like Django signals is doing its job in real-time when it listens to the updates on the database. When it notifies me that there is an update, I'd just call on my bunch of code that performs some notifications I want it to. Isn't this already in real-time? Do I or should I use Django channels here?

Thank you in advance for any help!


Solution

  • I have implemented something similar with Django. Here the main points:

    1. Sensors send new data to Django with a REST API (using DRF);
    2. Django processes the data. Heavy computation is achieved with Celery, instead of using signals, to close the connection with the client quickly;
    3. Then Celery updates the database with the processed data and uses Channels to notify front end's clients.

    Channels works best when used with WebSockets in the front end. It could be difficult at the beginning to have a full working production setup, yet the final result is usually very good for real time in-browser notifications in a modern and interactive way (ie: no page refresh).