What’s the easiest way to take an existing Django view and make it “real time” via long polling?
2nd October 2010
My answer to What’s the easiest way to take an existing Django view and make it “real time” via long polling? on Quora
I’d advocate decoupling your long polling endpoints entirely from the rest of your web app stack. Personally I like Node.js for this, but Tornado would work just fine too (I’ve experimented successfully with Tornado long polling in the past).
I wouldn’t even bother talking to the database from the long polling code. Instead, set it up as a sort of WebHook system. Your client starts long-polling a URL on the Tornado or Node.js server (which could be running on a sub-domain of your regular site, or could just be a separate part of the URL space proxied by something like nginx). That long polling server is set up to listen for WebHook POSTs to a protected URL, which can come from a backend process, a Celery worker, a Cron job or the Django web app itself. When the POST comes in, the long poll is instantly returned.
More recent articles
- Gemini 2.0 Flash: An outstanding multi-modal LLM with a sci-fi streaming mode - 11th December 2024
- ChatGPT Canvas can make API requests now, but it's complicated - 10th December 2024
- I can now run a GPT-4 class model on my laptop - 9th December 2024