๐Ÿš€ Software ยท LARZ-201 · Session 5 of 8

Background Work at Scale

Jobs, the scheduler, caching and email โ€” and how they behave across multiple gunicorn workers.

⏱ 10 min read📅 Updated 2026-07-25📊 Code examples throughout

Jobs, schedules, cache, email

@app.job
def send_receipt(email): ops.send_email(smtp, email, "Receipt", "...")

@app.schedule("0 3 * * *")
def nightly(): OldSession.where(created__lt=cutoff).delete()

@app.cache(ttl=60)
@app.get("/leaderboard")
def board(req): ...

The multi-worker gotcha

@app.job and @app.schedule run per gunicorn worker. Two safe patterns: run schedules in one dedicated process, or gate scheduled tasks behind a database lock so only one worker fires them. For heavy volume, swap app.jobs for a Redis-backed queue with the same enqueue() API.

Takeaways

  • Jobs/scheduler are per-worker โ€” plan for it (leader lock or dedicated process).
  • Cache read-heavy routes; send email off the request thread.

More in this course

Course home → · Browse all courses →