Part IV — Expert Production Engineering · Chapter 21 · Lesson 2 of 6 · 2 min read
Lesson 2: Authentication, Request Bounds, Concurrency, Timeouts, and Rate Limits
Lesson level: Expert
Purpose: Make admission and execution costs explicit before accepting prediction traffic.
Learning Objectives
- Configure caller authentication and payload limits.
- Distinguish concurrency, rate, and execution deadlines.
- Test denial paths without assuming cancellation stops running work.
2.1 Concepts
ServingConfig holds API-key and bearer-token sets plus record and byte limits. Empty authentication sets do not enforce authentication; configuring both sets requires both checks to pass. ResilientRuntime separately applies a client-scoped sliding-window rate limiter, bounded semaphore, and thread-pool wait timeout. The ordinary serving application is not automatically wired to this wrapper. Authenticate and authorize the external caller in the host before allocating expensive work, and derive client identity from that authentication rather than a supplied label.
2.2 Annotated Example
Verified Python configuration: ResilienceConfig(requests_per_minute=60, max_concurrency=8, request_timeout_seconds=30). These are source defaults, not recommended service objectives. A timed-out Future is cancelled opportunistically; already-running work may continue. The semaphore is released when the wrapper returns, so logical admission slots alone are not proof that physical work has stopped. Add process isolation or cooperative model cancellation where required.
2.3 Guided Practice
Draw the order of authentication, body-size enforcement, schema validation, rate admission, execution, and response. Explain which stages a reverse proxy must protect before the whole body is buffered.
2.4 Common Mistakes
Do not treat authentication as authorization, expose empty credential sets publicly, trust anonymous client IDs for quotas, or translate every failure into an undifferentiated success response.
2.5 Hands-On Lab
- Use a disposable credential and a supported local pipeline. Test valid, missing, and invalid authentication.
- Send a list at the configured record limit and one beyond it; repeat for the byte boundary.
- Use a controlled slow test double to reach concurrency and wait-timeout conditions.
- Record whether underlying work continues after timeout; add a bounded recovery policy.
Deliverable: Configuration, fixtures, observed results, and a control-coverage table. Pass only when every expected acceptance or rejection is demonstrated.
2.6 Review Questions
Why are byte and record limits separate? What happens when both credential sets are populated? Why is Future.cancel not a hard execution deadline?
2.7 Applied Challenge
Create host-level status mappings for authentication, invalid input, overload, and timeout. Audit all rejections without logging credentials or raw sensitive records.
Lesson Summary
Admission limits bound different resources. Secure serving combines authenticated identity, bounded parsing, explicit wrapper integration, and verified behavior under slow or abandoned work.
Lesson status: Draft complete; ready for review. Source-checked, not execution-validated.