Reading one RSS feed is easy. Polling two hundred feeds every hour and getting each article exactly once is where the small problems start. Here is what I learned building a feed reader for automations.
1. Ask the server whether anything changed
Most feed servers send an ETag or a Last-Modified header. Send them back on the next request and an unchanged feed answers 304 Not Modified with an empty body:
const res = await fetch(feedUrl, {
headers: {
...(state.etag && { 'If-None-Match': state.etag }),
...(state.lastModified && { 'If-Modified-Since': state.lastModified }),
},
});
if (res.status === 304) return []; // nothing new, nothing downloaded
It is polite to the publisher, and on a large list it removes most of the work.
2. Identify items by guid, then link, never by position
Feeds reorder items, re-list old ones and edit titles. The stable identity is, in order: the <guid> (RSS) or <id> (Atom); if there is none, the link; as a last resort, title plus date. Keep the identifiers you already delivered, per feed, and compare.
Do not use "published after my last run" as the only test. Many feeds have no dates, some publish items with a date in the past, and clocks differ.
3. Remember only what was safely saved
Write the "already seen" list after your items are stored, not before. If the run crashes in between, you get the items again next time instead of losing them. Duplicates can be removed later; a lost item is gone.
4. Expect broken XML
Real feeds mix RSS 2.0, RSS 1.0 (RDF), Atom and JSON Feed. They put HTML in CDATA or escape it, use relative links, declare old character sets, and write dates in several formats. A strict XML parser gives up on a surprising number of them.
5. Keyword filters need word boundaries
My first filter matched "AI" inside "available". Match whole words, and offer an explicit wildcard for endings.
The tool
I packaged this as RSS Feed Reader (I am the author). You give feed addresses, or just websites and the feed is found for you, turn on "only new items", and schedule it. On a test with eight addresses the first run returned 158 items; the second run a minute later returned 0, and four of the servers answered "not modified".
It costs $0.30 per 1,000 items returned. Unchanged feeds, failed feeds and items already delivered are free. A ready-to-run example: get new blog posts from competitor websites.
If you maintain your own poller, points 1 to 3 are the ones that matter most. And if a feed is read badly by the tool, send me its address.
Top comments (0)