Course contentsShow
← System Design
Lesson 1115 of 1,91928. Timeouts and DeadlinesFree lesson

Deadline Exceeded Error Handling

Proper error codes, cleanup procedures, and client handling when deadlines expire mid-request.

Deadline Exceeded Error Handling

What You'll Learn

You'll learn how to properly handle deadline expiration during request processing, including error codes, cleanup procedures, and appropriate client responses.

The Core Problem

When a deadline expires mid-request, your system faces a critical decision point: the work you're doing is now potentially worthless, but you might be halfway through a database transaction or holding locks. Proper deadline exceeded handling prevents resource leaks and helps clients respond appropriately.

Error Codes and Signaling

When a deadline expires, return specific error codes—not generic "internal server error." HTTP 504 Gateway Timeout or gRPC's DEADLINE_EXCEEDED status clearly communicate why the request failed. This distinction matters: clients should retry timeouts differently than validation errors.

Think of it like a restaurant's last call: if the kitchen is about to close and can't serve you, they tell you explicitly rather than just saying "service unavailable."

Cleanup Procedures

When you detect a deadline has passed:

  1. Stop ongoing work immediately to free resources
  2. Roll back partial transactions to maintain consistency
  3. Release locks and connections to prevent resource exhaustion
  4. Cancel downstream requests if they're still pending

Failing to clean up creates resource leaks that compound during high load—exactly when you can least afford them.

Client Handling

Clients receiving deadline exceeded errors should:

  • Not retry immediately—the operation took too long, so instant retry will likely fail again
  • Consider increasing timeout or breaking the request into smaller chunks
  • Log context about what was attempted for debugging
  • Present meaningful feedback to end users rather than cryptic error messages

Key Takeaway: Deadline exceeded requires immediate cleanup, specific error codes, and thoughtful client handling to prevent resource leaks and enable appropriate retry behavior—treat it as a distinct failure mode, not just another error.