Deciding what happens when.
DO IN THE REQUEST
Anything the visitor needs the result of immediately: displaying data, validating input, completing a purchase.
DO IN THE BACKGROUND
Sending email Processing or resizing images Generating reports Calling external APIs where the result is not needed immediately Syncing with other systems Cleanup
WHY
Work done during a request makes the visitor wait, risks timeouts, and holds an entry process open. Under load, this is what exhausts your limits.
ON SHARED HOSTING
Persistent workers are not available. The practical pattern is a cron job every minute or five minutes processing a queue with a time limit.
Jobs are processed in batches rather than instantly, which is acceptable for most purposes.
WHAT NEEDS TRUE REAL-TIME
Chat, live notifications, collaborative editing. These need persistent connections and a VPS.
THE TEST
Does the visitor need this to have happened before the page loads? If not, queue it.