Bounded queues and backpressure

15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.

An unbounded producer can exhaust memory when consumers are slower. Choose a bounded queue and a policy: wait, reject, or shed selected work. Cancellation and shutdown must wake blocked participants. Model a capacity of two, then explain what happens to a third job and how the caller learns the outcome.

Practice and evidence: Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.

queue=[]
capacity=2
for job in ["A","B","C"]:
    if len(queue)<capacity:queue.append(job)
    else:print("Rejected",job)
print(queue)

Expected result: Rejected C ['A', 'B']

Practice and evidence

Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.