What is 429 Status Code: Explanation and Usage
429 status code means "Too Many Requests". It tells the client that they have sent too many requests in a given time and should slow down to avoid being blocked.How It Works
Imagine you are at a busy coffee shop where the barista can only serve a certain number of customers at a time. If too many people order at once, the barista asks some to wait before placing more orders. The 429 status code works similarly in web servers.
When a client (like your browser or app) sends too many requests too quickly, the server responds with 429 Too Many Requests. This tells the client to slow down and try again later. This helps protect the server from overload and keeps the service stable for everyone.
Example
This example shows a simple server in Node.js that limits requests and returns 429 when the limit is exceeded.
import http from 'http'; let requestCount = 0; const MAX_REQUESTS = 5; const WINDOW_TIME = 10000; // 10 seconds const server = http.createServer((req, res) => { if (requestCount >= MAX_REQUESTS) { res.statusCode = 429; res.setHeader('Retry-After', '10'); res.end('429 Too Many Requests - please wait before retrying.'); return; } requestCount++; res.statusCode = 200; res.end('Request successful!'); }); // Reset count every WINDOW_TIME milliseconds setInterval(() => { requestCount = 0; }, WINDOW_TIME); server.listen(3000, () => { console.log('Server running on http://localhost:3000'); });
When to Use
Use the 429 status code when you want to protect your API or website from too many requests in a short time. This is common in public APIs to prevent abuse or accidental overload.
For example, if a user tries to log in repeatedly or a script sends many requests quickly, responding with 429 tells them to slow down. It helps keep your service reliable and fair for all users.
Key Points
- 429 means "Too Many Requests".
- It signals the client to slow down request rate.
- Often used with a
Retry-Afterheader to tell when to try again. - Helps protect servers from overload and abuse.