How API requests are signed, throttled and retried
Signature Version 4 from first principles, token-bucket throttling, which errors SDKs retry, backoff with jitter, and making retries safe.
How API requests are signed, throttled and retried
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Your secret key is never sent. The client hashes the request and signs it with a key derived from the secret, and AWS recomputes the same value.
- The derived signing key is scoped to one date, Region and service, and a signed request is only accepted close to its timestamp.
- AWS APIs throttle, commonly with token buckets: a burst capacity that refills at a steady rate, per account and Region.
- SDKs retry transient and throttling errors with exponential backoff and jitter. Errors such as AccessDenied or validation failures are not retried.
- A retry after a timeout may repeat an operation that already succeeded. Use client tokens or naturally idempotent calls.
- Retries multiply across layers. Retry in one place, cap the attempts, and let failures fail.
Proving who you are without sending the secret
Every AWS request arrives over the public internet asking to do something that may cost money or destroy data. The service has to know who sent it, that nobody altered it, and that it isn’t a recording of an old request. Sending your secret key with each call would solve the first problem and create a much worse one.
Signature Version 4 (SigV4) solves it with a keyed hash. You and AWS both know the secret. You use it to compute a fingerprint of this exact request, and AWS computes the same fingerprint and compares. Think of it as a wax seal that depends on the letter’s contents: change a word and the seal no longer fits.
The steps:
- Write the request in a canonical form: method, path, query, selected headers and a hash of the body.
- Hash that, and combine it with the timestamp and a scope of date, Region and service.
- Derive a signing key by chaining HMACs: secret, then date, then Region, then service.
- Sign the string with the derived key and put the result in the
Authorizationheader.
The chain in step 3 limits damage. A derived key works for one service in one Region on one day. The timestamp limits replay: in most cases a request must arrive within five minutes of it. With temporary credentials a session token header travels along too.
Doing it by hand
The algorithm fits in a few lines:
k = mac(mac(mac(mac(("AWS4" + secret).encode(), day), region), service), "aws4_request")
signature = hmac.new(k, to_sign.encode(), hashlib.sha256).hexdigest()
I signed an sts:GetCallerIdentity request this way with a dummy key and a fixed timestamp, then had botocore sign the same request. Nothing was sent:
scope 20261129/eu-west-1/sts/aws4_request
mine f8d82ce70b8d537e752244d6809040a975308c3022dfd08b3ca4c099636b6647
botocore f8d82ce70b8d537e752244d6809040a975308c3022dfd08b3ca4c099636b6647
In real work you let the SDK do this. Knowing the steps explains errors like SignatureDoesNotMatch, which usually means a wrong secret or something that rewrote the request on the way.
Throttling
The same API serves every customer, so each account gets a limited rate. EC2 documents its method as a token bucket, per account and Region. The bucket holds a number of tokens, each request removes one, and tokens refill steadily. The DescribeHosts example in the docs has a capacity of 100 and refills 20 per second: you can burst 100, then sustain 20.
Over the limit you get an error such as RequestLimitExceeded or ThrottlingException. This is normal behaviour, not a fault. Common causes are tight polling loops and many tools describing everything at once. Prefer events or waiters to polling.
What the SDK retries
SDKs sort failures into three piles:
- Transient (connection resets, timeouts, 500, 502, 503, 504): retry soon.
- Throttling: retry, starting from a longer delay.
- Everything else (
AccessDenied, validation errors, not found): fail immediately. Sending it again cannot help.
The delay grows exponentially and is randomised, which is jitter. Without it, clients that failed together retry together. In standard mode the default is 3 attempts in total (4 for DynamoDB), and a retry quota stops retries altogether when most calls are failing.
Two things to check in your own setup. Older tools still default to legacy mode (the CLI 1.44 used here does). And as of November 2026 the SDK reference says its newest timing and quota behaviour needs AWS_NEW_RETRIES_2026=true until it becomes the default.
I pointed boto3 at a small stand-in server that always answers ThrottlingException, with retries={"mode": "standard", "max_attempts": 3}:
request 1 at 0.00s
request 2 at 0.88s
request 3 at 1.80s
request 4 at 4.20s
gave up: ThrottlingException
Four requests, not three. In boto3’s Config object max_attempts counts retries, while total_max_attempts and the shared max_attempts setting count every attempt. The gaps are random: another run gave different ones.
Retries and doing things twice
A timeout does not mean nothing happened. The request may have succeeded and the response got lost. Reads and “set this value” calls are safe to repeat. Calls that create things are not, unless they accept an idempotency token, such as ClientToken on RunInstances: same token, same operation, one result. The general technique is covered in idempotent APIs, and the client-side patterns in circuit breakers and retries.
AWS is also often eventually consistent. A role you just created may not be usable for some seconds. Retry with backoff, don’t add a fixed sleep and hope.
About the video
The embed is a clip (19:55 to 39:00) of Shuffle Sharding’s “How AWS SIGv4 and SIGv4A work”, September 2021, a deep dive on request signing. The chapters in this range cover authentication, HMAC, deriving keys, what the signature binds, intermediate keys, Regional isolation and the move toward public-key signing (SIGv4A). It says nothing about throttling or retries, which the text covers. I judged it from chapters and description, since transcripts couldn’t be fetched. The short video in deeper covers backoff and jitter.
What was run: the signature comparison ran offline with botocore 1.42.97. The retry timings come from boto3 against a stand-in Python server, not from AWS. Time limits, error categories, default attempts and the EC2 bucket numbers are from AWS documentation, checked in November 2026.
Where this fits
You can now talk to AWS correctly. Before building on it, be clear which problems are yours: shared responsibility and the Well-Architected Framework.
Check yourself
A server's clock is twenty minutes slow and every AWS call is rejected, although the keys are correct. Why?
The timestamp is part of the signature and AWS generally requires the request to arrive within five minutes of it. Fix time synchronisation.
A thousand clients are throttled at the same instant and all retry after exactly one second. What happens, and what fixes it?
They collide again in a synchronised wave. Exponential backoff with random jitter spreads the retries out so the service can absorb them.
RunInstances times out. Is it safe to send it again?
Only with a client token. The first request may have launched instances. Sending the same ClientToken makes AWS treat the retry as the same request and not launch a second set.
Your code retries 3 times, it calls a service whose SDK makes 3 attempts. How many requests can one user action produce at the bottom?
If your code makes one call plus 3 retries and each call makes up to 3 attempts, that is 12 requests. Each extra layer multiplies again, which turns a brief slowdown into an overload.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.