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
- Weeknotes: asynchronous LLMs, synchronous embeddings, and I kind of started a podcast - 22nd November 2024
- Notes from Bing Chat—Our First Encounter With Manipulative AI - 19th November 2024
- Project: Civic Band - scraping and searching PDF meeting minutes from hundreds of municipalities - 16th November 2024