HerokuDavid GouldinProblem & solution
Django and Node together on Heroku
Summary
Django-based Heroku Connect needed realtime dashboard support through socket.io and Node.js, but Heroku apps could route traffic through only one dyno type. The team chose to run both stacks in one dyno using a runit buildpack and its sub-Procfile format: Node binds to PORT, while node-http-proxy forwards normal web requests to Gunicorn-hosted Django on 127.0.0.1:$DJANGO_PORT. This arrangement increases contention because processes share memory, CPU, and a filesystem, and it makes dyno logs less directly attributable; the team also flattened Procfiles into Procfile.local for Foreman-based local development. After running the architecture in production for a few months without issue, the team reported minimal proxy overhead and retained single-git-push deployment while establishing a path for websocket communication.
Context
Heroku Connect used Django for its platform app but needed Node.js and socket.io for a realtime dashboard. Because only one type of dyno can serve traffic for a Heroku app, the team had to choose between managing two applications or serving both stacks from one app.
Approach / What changed
A runit buildpack and sub-Procfile format run Node.js and Django in the same dyno. Node binds to PORT and uses node-http-proxy to send normal web traffic to Gunicorn, which binds Django to 127.0.0.1:$DJANGO_PORT. A flattened Procfile.local preserves Foreman-based local development.
Takeaways
Heroku permits only one dyno type to serve an app’s traffic, creating a choice between separate apps or co-locating Node.js and Django.
With node-http-proxy, Node.js binds to PORT and forwards normal web traffic to Django bound by Gunicorn at 127.0.0.1:$DJANGO_PORT.
Co-locating processes increases shared resource contention and complicates log attribution, but production ran without issue for a few months and proxy overhead was minimal.
Source and freshness
- Source
- heroku.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.