Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Your public feed endpoint receives 3,000 requests per second from feed readers polling every minute, and each request queries the database. How do you reduce the load?

The feed changes perhaps a few times a day, yet we rebuild it from the database 3,000 times a second, so the fix is to stop doing work per request. Generate the feed once when content changes, or cache it in memory with a short TTL, put a CDN in front with Cache-Control max-age so it absorbs most traffic, answer conditional requests with 304 Not Modified using an ETag or Last-Modified, offer WebSub so subscribers get pushes instead of polling, and rate-limit clients that poll abusively.

Why this question is asked

Load problems like this are common for any public endpoint that many machines poll: feeds, status pages, configuration files and price lists. The interviewer wants to see that we look at the ratio between how often data changes and how often it is read, and then move the work to the cheapest layer that can do it. In this answer, we will look at why the current setup is wasteful, then go layer by layer: generate once, cache at the edge, answer with 304, push instead of poll, and control abusive clients, finishing with the numbers we would expect afterwards.

1Understanding Why the Load Is So High

Let us first put numbers on the problem. 3,000 requests per second is 180,000 per minute, which matches about 180,000 subscribers polling once a minute. Each request runs a query for the latest 20 posts, builds XML and sends perhaps 40 KB. That is 3,000 queries per second and roughly 120 MB per second of outgoing traffic.

Now compare that with how often the feed changes. A busy blog publishes maybe 10 posts a day. So out of about 260 million requests a day, all but 10 moments produce exactly the same bytes as the request before. Every layer of the stack is redoing work whose answer is already known. Notice that the question is not how to make the query faster; it is how to stop running it.

2Generate the Feed Once, Not Per Request

The first fix moves the work from read time to write time. When a post is published or edited, we build the feed XML once and keep the bytes, along with an ETag and the last-modified time. Requests then serve those bytes straight from memory. If we run several instances, each can rebuild on an event, or we write the file to object storage and serve it from there.

Java
@Component
class FeedCache {
private volatile Rendered current = Rendered.EMPTY;
@EventListener(PostPublished.class) // also on edit and unpublish
void rebuild() {
byte[] xml = renderer.render(posts.latest20()); // one query per change, not per request
current = new Rendered(xml, "\"" + sha256(xml) + "\"", Instant.now());
}
Rendered get() { return current; }
}
@GetMapping(value = "/feed.atom", produces = "application/atom+xml")
ResponseEntity<byte[]> feed(WebRequest req) {
Rendered r = feedCache.get();
if (req.checkNotModified(r.etag(), r.modified().toEpochMilli())) return null; // 304
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(Duration.ofSeconds(60)).cachePublic())
.body(r.xml());
}

If event-driven rebuilding is hard to wire up, a simple in-memory cache with a short TTL, for example 30 to 60 seconds with Caffeine, has almost the same effect: at most one query per instance per minute, instead of thousands per second. The cost is that a new post may appear up to a minute late, which feed readers that poll every minute will not notice.

3Let the CDN Serve the Feed

The feed is the same for everyone and public, which makes it ideal for a CDN, a network of caching servers close to the clients. With Cache-Control: public, max-age=60 the CDN keeps a copy for 60 seconds per edge location and answers all requests in that window itself. Our origin then sees roughly one request per edge location per minute, which is a few requests per second at most, instead of 3,000.

We can go further with stale-while-revalidate, which lets the CDN keep serving the old copy for a short time while it fetches a fresh one, so a slow origin never shows up as a slow feed. When a post is published, we can also purge the feed URL at the CDN so the new entry appears at once instead of after the max-age.

Step throughWhere each request is answered after the fix
  1. Feed readermay skip the request entirely if it honours max-age
  2. CDN edgeanswers almost all requests from its copy, 200 or 304
  3. Spring Boot instancea few requests per second, served from memory
  4. In-memory rendered feedrebuilt only when a post changes
  5. Databasequeried a few times a day

5 layers, from the top down. Step through them one at a time.

Each layer absorbs most of the traffic before it reaches the one below.

4Return 304 Not Modified for Conditional Requests

Most feed readers send If-None-Match with the ETag they saw last, or If-Modified-Since with the last Last-Modified value. When the feed has not changed, we answer 304 Not Modified with no body. The request still arrives, but it carries a few hundred bytes of headers instead of 40 KB, which cuts the bandwidth by more than 99 percent for unchanged polls.

CDNs understand these headers too: a CDN can answer a conditional request from its cache with 304, and it revalidates with our origin using the same headers. The controller above already does this with WebRequest.checkNotModified, and because the ETag is precomputed, a 304 costs us almost nothing.

5Push Instead of Poll With WebSub

Polling every minute is wasteful by design, because subscribers ask whether anything changed far more often than it does. WebSub, a W3C standard previously known as PubSubHubbub, turns this around. The feed advertises a hub with a link rel="hub" element. Subscribers register a callback URL with the hub. When we publish a post, we notify the hub, the hub fetches the feed once and pushes the update to every subscriber's callback.

Step throughWebSub delivering a new post
SubscriberHubOur site
subscribe: topic feed.atom, callback URL
verify the callback with a challenge
publish ping: feed.atom changed
GET /feed.atom once
POST the new content to the callback

5 messages in order. Play them, or step through them one at a time.

One fetch by the hub replaces thousands of polls.

The catch is that only some clients support WebSub, mostly aggregators and services rather than desktop readers, so it reduces polling from those clients but does not remove polling in general. We can run our own hub or use a hosted one.

6Rate-Limiting Abusive Clients

Some clients ignore caching entirely, poll every second, or never send conditional headers. With a CDN in front, they mostly hurt the CDN bill rather than our database, but we should still find them in the access logs, grouped by IP address and user agent, and limit them. A rate limit of, say, 60 requests per minute per IP at the CDN or gateway, answering 429 Too Many Requests with a Retry-After header, is enough for any legitimate reader.

Before blocking, it is worth contacting the owner of a well-known aggregator, since misbehaving clients are often a configuration bug. And we should keep the limit generous for shared IPs, such as corporate proxies, where many real readers appear as one address.

7Follow-up questions

Is a 60 second max-age too long for a news site?

It depends on the business. For breaking news, we can lower max-age to 10 or 15 seconds and purge the CDN on publish, which still cuts origin load by a huge factor. The key insight is that even a few seconds of caching turns thousands of requests per second into a handful.

Why not just add database read replicas?

Replicas would spread 3,000 identical queries over more machines, which costs money and still builds the same XML thousands of times. Caching removes the repeated work instead of paying for more capacity to do it.

How do we keep several instances consistent when the feed is cached in memory?

Each instance can rebuild when it receives the publish event, for example through a message topic, or all instances can read the rendered feed from shared storage. Small differences of a few seconds are acceptable because the ETag changes with the content, so clients simply see the new version on their next poll.

8Conclusion

In this answer, we saw that the feed endpoint was rebuilding the same output thousands of times a second for content that changes a few times a day. We generated the feed once on change or cached it with a short TTL, made the CDN the main serving layer with Cache-Control max-age, answered conditional requests with 304 Not Modified using ETag and Last-Modified, offered WebSub so supporting subscribers receive pushes, and rate-limited abusive clients by IP and user agent. Together these bring the database down from 3,000 queries a second to a few a day.

What to say in the interviewAbout 80 seconds aloud

Open with

The first thing I notice is the ratio. The feed changes maybe ten times a day, but we are running the query and building the XML 3,000 times a second, so almost every request produces the same bytes as the one before.

Then, if they want more

I would stop doing work per request. First, generate the feed once when a post is published or edited and keep the bytes and an ETag in memory, or, if that is hard to wire up, cache the rendered feed for 30 to 60 seconds.

Second, put a CDN in front and send Cache-Control public with a max-age of about a minute, plus stale-while-revalidate, and purge the URL on publish. Then the origin sees a few requests per second instead of 3,000.

Third, support conditional requests: with WebRequest.checkNotModified and the precomputed ETag and Last-Modified, readers that send If-None-Match get a 304 with no body, which removes almost all the bandwidth. Fourth, advertise a WebSub hub in the feed, so aggregators that support it get pushes instead of polling.

And finally, I would look at the access logs by IP and user agent and rate-limit clients that poll every second or ignore caching, returning 429 with Retry-After. After that the database is queried a few times a day.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your public feed endpoint receives 3,000 requests per second from feed readers polling...": https://scrivio-interview-library.netlify.app/spring-boot/web-other/fd354445d1/