SoloMedium5m

The Unbounded Queue OOM

#sre-critical — notification-worker OOM after 4 hours

SRE: Web server enqueues 500 welcome emails/sec; worker sends 10/sec. Junior dev used unbounded asyncio.Queue() + put_nowait() — queue hit millions of items, 16GB RAM, Exit 137.

The trap: Fast producer + slow consumer + unbounded buffer = memory bomb.

Your task

Fix `WelcomeEmailService` in `email_queue_service.py`: bounded queue (maxsize=1000) + await queue.put() for backpressure.

Book: queue decouples work · Prod: unbounded queue OOMs the pod — slow the producer.

Skills you'll prove

algorithmspythonasyncioproducer-consumerbackpressurequeuesmemory-managementbackendbook-vs-prod

Interview Tip

When asked about queues or producer–consumer patterns, say: "A queue between a fast producer and slow consumer is only safe if it's bounded. I debugged a notification service where the API enqueued 500 welcome emails per second but workers sent 10 per second — the dev used an unbounded in-memory queue with put_nowait. After four hours the queue hit millions of items and OOM'd the pod. The fix wasn't faster workers first — it was a bounded queue with backpressure so the web server slows down when the queue is full. In production, every buffer needs a max size or a drain rate guarantee."

Browse freely — sign in when you're ready to open a ticket and prove your skills.