|
|
|
Ask HN: Is async request processing possible with Python Django?
|
|
4 points
by anon_founder
4508 days ago
|
|
I started with Python Django to build my web app since it was mostly short-lived http requests rendering UI. As the product matured, now I realize that I need to support lot more web service calls (with no UI component). The web service calls need to be processed and responded to asynchronously for 2 reasons: 1) My code may call another web service in turn to get some data to service the call and I don't want to hold the original thread or process while doing so and 2) Certain requests can only be responded to after certain events happen on the backend and I don't want to hold the thread/process blocking and waiting for that event. The more I think about it, the more it sounds like I may need something like nginx for my web service calls (from whatever I have heard about nginx). Can python django really be used in this manner with an appropriate web server and a set of middleware components? If so, can you recommend a particular stack choice? If not, what are my options and can you educate me on the pros and cons of those choices? |
|
1. Long polling: It’s definitely possible to have thousands of long-lived requests with something like gunicorn/tornado. Remember to turn-off buffering in your front-end nginx proxy if you want to use long-polling.
2. Async with web hooks. Gather the request payload, push it to a job queue, and return the response. Process the job queue at your leisure and then call the web hook when complete. You can use celery, beanstalk or my personal choice rq (and django-rq.)