CHAPTER 16 · Scaling and Infrastructure · 4 / 10
Move heavy work off the request path
CPU/memory-heavy or slow work (document conversion, OCR, large bulk extraction) shouldn't run inside the request that holds a user's connection. As load grows, move it to background workers fed by a queue:
- The request enqueues a job and returns quickly (with a
processingstatus; Chapter 9). - Workers pull jobs, do the heavy work, and update status; the client polls or subscribes for completion.
- Workers scale independently of the web tier, so a burst of uploads doesn't starve interactive chat.
As emphasized in Chapter 10, design for this from the start with status fields even if you begin synchronous; the migration to workers is then localized.