Scrivio Interview library
CodingFoundations7 min read · updated 12 November 2026

Expose an Atom feed of the 20 latest blog posts from a Spring Boot application. Which libraries or approaches would you use, and which HTTP features make feeds cheap for clients that poll?

I would build the feed with the ROME library, returning a com.rometools.rome.feed.atom.Feed from a Spring MVC controller so that Spring's Atom message converter writes it as application/atom+xml, or render it with a template engine if I want full control of the XML, taking care with escaping. To make polling cheap, the response carries an ETag and Last-Modified so readers get 304 Not Modified with no body, a Cache-Control header so CDNs and readers can cache it, and every entry has an absolute link and a stable id so readers never show duplicates.

Why this question is asked

Feeds look old-fashioned, but they are still how podcast apps, feed readers, aggregators and many automation tools follow a site. A feed is also a nice small interview problem because it combines building correct XML with HTTP caching, and a feed that ignores caching gets polled thousands of times a day by clients that only want to know whether anything changed. In this answer, we will recap what an Atom feed contains, build one with ROME in Spring Boot, look at the template alternative, make polling cheap with conditional requests and caching, and see why ids and URLs must be stable.

1A Quick Recap of an Atom Feed

An Atom feed is an XML document, defined by RFC 4287, that lists the latest items of a site. The feed itself has an id, a title, an updated timestamp and a link to the site. Each item, called an entry, has its own id, title, updated time, a link to the full page, and a summary or the content.

Feed readers poll this document, often every 15 to 60 minutes, and show any entry whose id they have not seen before. That last point matters: the entry id is how a reader recognises a post, so if it changes, the reader shows the post again as new.

XML
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://blog.example.com/</id>
<title>Example Blog</title>
<updated>2026-11-05T09:30:00Z</updated>
<link rel="self" href="https://blog.example.com/feed.atom"/>
<entry>
<id>tag:blog.example.com,2026:post-1042</id>
<title>Streaming Excel exports</title>
<updated>2026-11-05T09:30:00Z</updated>
<link href="https://blog.example.com/posts/streaming-excel-exports"/>
<summary>How we stopped running out of memory.</summary>
</entry>
</feed>

2Building the Feed With ROME

ROME is the standard Java library for RSS and Atom. It models feeds as Java objects and writes valid XML for us. Spring MVC has an Atom message converter, AtomFeedHttpMessageConverter, which it registers automatically when ROME is on the classpath, so a controller can simply return a ROME Feed object. Spring also has older view classes, AbstractAtomFeedView and AbstractRssFeedView, built on ROME, but returning the object through the converter is the simpler modern style.

Java
// build.gradle: implementation 'com.rometools:rome:<current version>'
@RestController
class FeedController {
private final PostRepository posts;
FeedController(PostRepository posts) { this.posts = posts; }
@GetMapping(value = "/feed.atom", produces = "application/atom+xml")
Feed feed() {
List<Post> latest = posts.findTop20ByPublishedTrueOrderByPublishedAtDesc();
Feed feed = new Feed("atom_1.0");
feed.setId("https://blog.example.com/");
feed.setTitle("Example Blog");
feed.setUpdated(Date.from(latest.isEmpty() ? Instant.EPOCH : latest.get(0).getUpdatedAt()));
feed.setEntries(latest.stream().map(this::entry).toList());
return feed; // written by AtomFeedHttpMessageConverter
}
private Entry entry(Post p) {
Entry e = new Entry();
e.setId("tag:blog.example.com,2026:post-" + p.getId()); // stable, never the title
e.setTitle(p.getTitle());
e.setUpdated(Date.from(p.getUpdatedAt()));
Link link = new Link();
link.setHref("https://blog.example.com/posts/" + p.getSlug()); // absolute URL
e.setAlternateLinks(List.of(link));
Content summary = new Content();
summary.setValue(p.getSummary()); // ROME escapes the text for us
e.setSummary(summary);
return e;
}
}

Notice that the query asks only for the 20 latest published posts, and that ROME handles escaping, so a title such as Tips & Tricks <2026> comes out as valid XML. ROME also uses java.util.Date in its model, so we convert from Instant at the edge.

3The Template Alternative

We can also render the feed with a template engine such as Thymeleaf in XML mode, or with a small hand-written writer. This gives full control, for example for custom namespaces, but it moves two responsibilities onto us. First, escaping: every title, summary and URL must be XML-escaped, otherwise a single ampersand or angle bracket in a post title breaks the whole feed for every reader. Templates in XML mode escape output by default, and we must not switch that off. Second, the content type: the response must be application/atom+xml (or at least a valid XML type), set with produces or on the ResponseEntity, so readers and browsers treat it as a feed.

4Making Polling Cheap With Conditional Requests

Most polls find nothing new, so the cheapest response is no body at all. HTTP conditional requests do exactly that. We send an ETag, a fingerprint of the response, and a Last-Modified time. A polite reader sends them back next time in If-None-Match and If-Modified-Since. If nothing changed, we answer 304 Not Modified with an empty body.

Java
@GetMapping(value = "/feed.atom", produces = "application/atom+xml")
ResponseEntity<Feed> feed(WebRequest request) {
Instant last = posts.latestUpdateTime(); // one cheap indexed query
String etag = "\"" + last.toEpochMilli() + "\"";
if (request.checkNotModified(etag, last.toEpochMilli())) {
return null; // Spring sends 304 with no body
}
return ResponseEntity.ok()
.cacheControl(CacheControl.maxAge(Duration.ofMinutes(5)).cachePublic())
.body(buildFeed()); // headers ETag and Last-Modified already set
}
// First request: 200, body about 30 KB, ETag "1793871000000"
// Second request: 304, no body, no feed built
Step throughA reader polling a feed that has not changed
Feed readerSpring controllerDatabase
GET /feed.atom, If-None-Match "1793871000000"
select max(updated_at)
same timestamp
304 Not Modified, no body

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

Only one indexed query runs, and no XML is built or sent.

WebRequest.checkNotModified() compares the request headers with our values, sets the ETag and Last-Modified headers, and tells us whether we can stop. The reason this version saves real work is that we check a single timestamp before loading 20 posts.

Spring also offers ShallowEtagHeaderFilter, which computes an ETag by hashing the response body. It is a one-line change and saves bandwidth, because the client still gets 304, but it saves no server work: the feed is built in full every time just to compute the hash. For a feed endpoint, checkNotModified is the better tool.

5Cache-Control, Absolute URLs and Stable Ids

Cache-Control: public, max-age=300 lets a CDN in front of the site serve the feed for five minutes without asking us, and lets readers skip a request entirely if they respect it. For a blog, a few minutes of delay is fine and removes most of the load.

Links in a feed must be absolute, such as https://blog.example.com/posts/streaming-excel-exports, because the feed is read outside our site and a reader has no page to resolve a relative path against. Ids must be stable and unique forever. A good pattern is a tag URI built from the domain, a year and the database id. We should never use the title, which an editor may fix, or a URL that may change when the slug changes, because readers would then show the same post twice.

6Follow-up questions

What is the difference between RSS 2.0 and Atom?

Both are XML feed formats. RSS 2.0 is older and looser: its specification is short, many elements are optional, the item guid is optional, dates use the RFC 822 format, and the content type of a description is not stated, so readers guess whether it is HTML. Atom is an IETF standard, RFC 4287, with stricter rules: every feed and entry must have an id, a title and an updated time, dates use RFC 3339, and content declares its type as text, html or xhtml. Atom is easier to process correctly; RSS is still very widely supported, so some sites publish both.

Why not generate the XML with string concatenation?

Because escaping is easy to forget and one unescaped character breaks the feed for every subscriber. A library like ROME, or a template engine in XML mode, escapes values for us and produces well-formed XML.

Should the feed include full content or only summaries?

It is a product choice. Full content is friendlier to readers but makes the feed larger and exposes all text to scrapers. Summaries keep the feed small and bring readers to the site. Either way, conditional requests and caching keep the cost of polling low.

7Conclusion

In this answer, we built an Atom feed of the 20 latest posts with ROME, returning a Feed object that Spring's Atom converter writes as application/atom+xml, and saw that a template engine also works if we keep escaping on and set the content type. We made polling cheap with ETag and Last-Modified through WebRequest.checkNotModified, so unchanged polls get 304 with no body, noted that ShallowEtagHeaderFilter saves bandwidth but not work, added Cache-Control for CDNs and readers, and used absolute URLs and stable entry ids so readers never show duplicates.

What to say in the interviewAbout 90 seconds aloud

Open with

I would use the ROME library, which models Atom and RSS feeds as Java objects. In Spring MVC, if ROME is on the classpath, the Atom message converter is registered, so my controller can return a ROME Feed and it is written as application/atom+xml.

Then, if they want more

I would query only the 20 latest published posts, map each to an Entry with a title, an updated time, an absolute link and a summary, and let ROME do the XML escaping.

Spring also has the older AbstractAtomFeedView based on ROME, and I could use a template engine instead, but then I have to make sure escaping stays on and the content type is right. The important part is making polling cheap, since most polls find nothing new.

I would compute the last update time with one cheap query, use it as the ETag and Last-Modified, and call WebRequest.checkNotModified, so a reader that sends If-None-Match or If-Modified-Since gets a 304 with no body and we never build the feed. ShallowEtagHeaderFilter is simpler but still builds the whole body to hash it.

I would add Cache-Control with a few minutes of max-age so a CDN can serve it. Finally, entry ids must be stable, like a tag URI with the post id, and links absolute, so readers never show a post twice.

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 "Expose an Atom feed of the 20 latest blog posts from a Spring Boot application. Which...": https://scrivio-interview-library.netlify.app/spring-boot/web-other/06454829fd/