What’s your typical async application look like in Django? I’m starting to dip my toes in after primarily just working sync and am running in to brick wall after brick wall.
I’ve got a “toolbox” app at work with a few small Django apps to help out our small department in various things and wanted to async something to deal with GitHub webhooks. Using Django 5.0 and daphne.
@josh no, definitely not. You're voicing the reason we've been trying to implement it for the past few years. I'm excited to see how much of it we can achieve.
I'm a bit worried about how we instrument SSE or other responses that aren't tied to an explicit request. But we'll figure something out!
Any good blogs or docs about real world Django async usage? My searching is mostly coming up empty with beginner tuts about the initial setup, which I got down.
@josh Yes, this. Run your main app with WSGI, as you always did. Then run a little sidecar, handling all your ASGI bits, for where you actually need async: long-lived connections, realtime updates, two-way comms.
You can do the whole app as ASGI but WSGI scaling patterns are super well known, and all the edge cases have been dealt with over the years.
@carlton@josh Would this "ASGI sidecar" be a different Django project with e.g. a different INSTALLED_APPS configuration (e.g. only async-compatible apps)? Do you know any articles or example projects?
@romanroe@josh not normally I’d say. (Like you can do all that if you need to, but likely you don’t.) Literally you’re just serving an asgi.py instead of a wsgi.py.
Your asgi app maybe has Channels bits. Maybe has a different URLConf, to only serve the URLs you want. Maybe different middleware…
BUT your reverse proxy has to decide which requests to route where, so likely you don’t need to be too clever.
One of those moments as a self-taught programmer where something comes to you as the simple solution but you're not totally sure it's the CORRECT and BEST way to do something. Even as I add notches to my belt as the years go on, still hard to shake that feeling sometimes.
@carlton Side note, I'm not sure why the phrase 'notches in the belt' came to my head to refer to experience or where I've ever heard it before, but I liked the way it sounded. 😄 Looking up the source of the idiom, I found this quora post with one possible source - "A notch in one’s belt is an expression from the U.S. Old West that refers to counting the number of people one has killed." Morbid!
Add comment