Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Scaling AI Systems

Free · sign in to start and track progress

1 · Throughput under limits

  • 1Rate limits and quotas
  • 2Concurrency and flow control

    Exercise answers

    • Answer: Build and test a token-aware, fair limiter
    • Answer: Adaptive concurrency under a moving limit
  • 3Retries, backoff and overload
  • 4Backpressure, load shedding and batching

2 · Latency, resilience and capacity

  • 5Latency engineering for agents
  • 6Response caching and failover
  • 7Load testing and capacity planning
CapstoneMonth-end readiness for an agent fleetReference implementation

Module 1 · Throughput under limits · Lesson 2

Concurrency and flow control

Size how many model calls to keep in flight with Little's law, build a token-aware limiter in async Python, share it across workers, adapt it to what the provider tells you, and keep one customer's backlog from starving the others.

75 min 1 video 3 exercises 7-question quiz Answers
Setup for the exercises:Install Claude CodePython with uv

By the end of this lesson you can

  • Compute the concurrency needed to use a rate limit fully with Little's law, and explain why more concurrency past that point only adds queueing
  • Implement an async limiter that combines a concurrency cap with token buckets denominated in tokens, and reconciles estimates with actual usage
  • Share a limiter across many workers with an atomic Redis token bucket, and explain the trade-off against static partitioning
  • Adapt the concurrency limit to 429s and latency, and explain the link to TCP congestion control
  • Schedule work fairly across customers with token-weighted deficit round robin, and quantify the effect on waiting times

On this page

  • Intuition: lanes on a motorway
  • Little's law gives the right number
  • Worked example
  • Two controls, not one
  • Sharing the limit across workers
  • Adapting to what the provider tells you
  • Fairness across firms
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: lanes on a motorway
  2. 02Little's law gives the right number
  3. 03Two controls, not one
  4. 04Sharing the limit across workers
  5. 05Adapting to what the provider tells you
  6. 06Fairness across firms
  7. 07Misconceptions and limits
  8. 08Connections
  9. 09Summary

Sources & further reading

  • Fairness in Serving Large Language ModelsPaper · Sheng et al. · 2024OSDI 2024. The Virtual Token Counter scheduler counts each client's served tokens and serves the least-served client next. Read the introduction and the description of the Virtual Token Counter; the per-firm scheduler in this lesson is a simplified client-side version.
  • Handling Overload (Site Reliability Engineering, chapter 21)Lab research · Alejandro Forero Cuervo · Google · 2016Client-side adaptive throttling, per-customer limits and criticality. Read "Client-side throttling" for how clients shed load locally once backends start rejecting.
  • Performance Modeling and Design of Computer SystemsBook · Mor Harchol-Balter · Carnegie Mellon University · 2013The standard queueing text for computer systems. Chapter 6 states and proves Little's law for open and closed systems; it is the basis for this lesson's sizing rule.
  • Netflix concurrency-limitsDocs · NetflixA production library that treats a service's concurrency limit like a TCP congestion window and adjusts it from latency and drops (Vegas, Gradient2, AIMD). The README's background section is the clearest short case for adaptive limits.
  • Upstash Ratelimit for Python, algorithmsDocs · UpstashServerless, Redis-backed fixed-window, sliding-window and token-bucket limiters for Python. Good for per-firm request limits across serverless workers.
  • asyncio synchronization primitivesDocs · Python Software FoundationSemaphore and Lock semantics, which the limiter code relies on.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 9 more sections
  • 3 hands-on exercises
  • A 7-question quiz
  • Progress, quiz scores and bookmarks