Parsing a feed takes one library call. The work in a news aggregator is everything around that call: fetching hundreds of feeds without hammering anyone, coping with feeds that are broken in creative ways, recognizing the same story twice, and storing it all so the reading side is fast. This is a walk through those parts, based on what we learned crawling a few thousand feeds for our directory.
Start with the feed list
The list of sources is the product. Store each feed with its address, the site it belongs to, a fetch interval and the state from the last fetch: HTTP status, ETag, Last-Modified, the time of the last success and a count of consecutive failures.
Begin with sources you have checked by hand. Our news category lists the main feeds of newspapers, broadcasters and wire services with the address we verified, which saves the guesswork of finding feeds yourself. When you add a source by site address, use the link rel="alternate" tags on the home page first and fall back on common paths like /feed/ and /rss.xml. In our crawl, link tags found the feed on 1,448 sites and guessing common paths on another 426.
Fetch politely
A naive fetcher downloads every feed every five minutes. That wastes bandwidth on both ends and gets you blocked. Three habits fix it.
Use conditional requests. Save the ETag and Last-Modified headers from each response and send them back as If-None-Match and If-Modified-Since. A server that supports them answers 304 Not Modified with an empty body, and you skip parsing entirely. On slower feeds most fetches end this way.
Adapt the interval to the source. A wire service publishing every few minutes deserves a short interval; a personal blog that posts twice a month can be fetched every few hours. A simple rule works: look at the gaps between the last ten items and fetch at roughly half the median gap, clamped between 10 minutes and 12 hours.
Back off on errors. Treat 429 Too Many Requests and 503 as a request to slow down, and read the Retry-After header if present. After repeated failures, double the interval each time up to a ceiling, and alert yourself when a feed has been failing for days.
Identify yourself. Send a User-Agent that names your aggregator and links to a page explaining what it does, the way our own fetcher points to its page:
User-Agent: ExampleNews/1.0 (+https://example.com/bot)
Site owners who see an unknown bot in their logs block it. Site owners who can read who you are and how to reach you usually let it through. Expect a share of sites to block you anyway: 1,023 of the 5,518 sites in our last crawl answered with a 403 or a challenge page.
Handle redirects deliberately. Follow them, but when a feed answers with a permanent redirect (301 or 308), update the stored address so you go straight to the new one next time. Do not update on 302 or 307.
Parse with a library
In Python, feedparser handles RSS 0.9x, 1.0, 2.0 and Atom, and it accepts the cached headers directly:
import feedparser
d = feedparser.parse(feed.url, etag=feed.etag, modified=feed.modified,
agent="ExampleNews/1.0 (+https://example.com/bot)")
if d.get("status") == 304:
return [] # nothing new
feed.etag = d.get("etag")
feed.modified = d.get("modified")
for e in d.entries:
print(e.get("id"), e.get("link"), e.get("title"), e.get("published_parsed"))
feedparser is also forgiving. When the XML is broken it sets d.bozo and still returns what it could read, which matters: 165 of the working feeds in our directory failed strict validation, and readers are expected to cope.
In Node.js, rss-parser gives a similar normalized result for RSS and Atom. If you need full control, fast-xml-parser turns the XML into objects and you map the fields yourself. Either way, do the HTTP request yourself so you control headers, timeouts and size limits; cap the body at a few megabytes and the request at 15 to 20 seconds.
Recognize items you have already seen
Every fetch returns mostly items you already have. To tell new from old, build a key for each item in this order:
- The
guid(RSS) orid(Atom), if present. - The item link, normalized: lowercase host, no fragment, and tracking parameters like
utm_sourceremoved. - A hash of the title and the publication date, when neither of the above exists.
Store the key with a unique constraint and insert with "ignore on conflict". Be aware of two traps. Some feeds put tracking parameters in the guid, so it changes on every fetch. Others reuse one guid for several items. If one source produces a burst of "new" items with titles you already have, the identifier is unstable and that source needs the link-based key instead.
Normalize dates
Store every date in UTC. RSS dates follow RFC 822 (Thu, 26 Nov 2026 07:30:00 +0100), Atom uses RFC 3339 (2026-11-26T06:30:00Z), and plenty of feeds use neither. feedparser's published_parsed already returns a UTC time tuple. When an item has no date, use the time you first saw it rather than leaving it empty, and keep both values. If a date lies more than a day in the future, clamp it to the fetch time, or the item will sit at the top of your front page for weeks.
Clean the HTML
Feed content is HTML written by strangers. Never insert it into your pages as it is. Run it through a sanitizer with an allow list of tags and attributes: DOMPurify in JavaScript, or nh3 in Python (bleach, the long-standing choice, is deprecated). Strip scripts, iframes, inline event handlers and style attributes. Resolve relative links and image addresses against the item link, because a surprising number of feeds use them.
A storage sketch
Two tables carry most aggregators a long way:
CREATE TABLE feeds (
id INTEGER PRIMARY KEY,
url TEXT NOT NULL UNIQUE,
site_url TEXT,
title TEXT,
etag TEXT,
last_modified TEXT,
interval_min INTEGER NOT NULL DEFAULT 60,
next_fetch_at TIMESTAMP NOT NULL,
failures INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE items (
id INTEGER PRIMARY KEY,
feed_id INTEGER NOT NULL REFERENCES feeds(id),
item_key TEXT NOT NULL,
url TEXT,
title TEXT,
summary TEXT,
published_at TIMESTAMP NOT NULL,
seen_at TIMESTAMP NOT NULL,
UNIQUE (feed_id, item_key)
);
CREATE INDEX items_published ON items (published_at DESC);
The scheduler is a query for feeds where next_fetch_at has passed, ordered by that column. After each fetch, set the next time from the interval and the failure count.
Group the same story across sources
When ten outlets cover the same event, readers want one entry with ten links, not ten entries. Full clustering is a research topic, but a light version gets most of the benefit: compare new titles against titles from the last 48 hours using word overlap (Jaccard similarity on lowercased words without stop words), and group pairs above a threshold you tune by eye. Matching outbound links helps too, since many stories cite the same original source. Keep the grouping in a separate table so a bad match can be undone.
Respect the publishers
Most news feeds carry a headline and a short summary on purpose. Show that, credit the source by name, and send readers to the original article. Republishing full text from a feed that offers it is still copying, and many publishers' terms forbid it. A clear link back is also what keeps sites willing to let your fetcher in.
If you would rather not run the crawling yourself, our directory data is available to software as well: the API checks a feed on demand, and the MCP server lets AI assistants look up verified feed addresses by site or subject. Either one is a quick way to seed the feed list before your own fetcher takes over.