logo
Parslinks
Back to blog
Platform4 min read

Do you need a CDN? When it speeds you up, and when it's just another bill

A CDN works wonders for static files. For pages rendered from the database on every request, it usually does very little.

Ehsan Yaghmori

Founder & CTO, Parslinks

A small ticketing startup sells seats for indie concerts. Most weeks are quiet. Then a popular band announces a surprise show, the link goes viral, and the event page takes six seconds to load. In the incident channel, someone writes the obvious thing: "We need a CDN."

Maybe. A CDN is a network of servers close to your users that keep copies of your responses. The key word is copies. A CDN can only speed up something it's allowed to copy and hand to the next person.

What a CDN actually does

When a visitor in Lisbon requests your logo, the nearest CDN node answers instead of your origin server in Frankfurt. If that node doesn't have the file yet, it fetches it once and keeps it for everyone who asks next.

That gives you two benefits:

  • Lower latency for users far from your origin.
  • Less load on your origin, because most static requests never reach it.

What benefits, and what doesn't

What actually benefits from a CDN?

Static assets: the ideal case

Hashed JS and CSS bundles (app.3f9a1c.js), fonts and product images are identical for everyone and never change under the same name. Serve them with Cache-Control: public, max-age=31536000, immutable and a CDN can hold them for a year. We cover the headers in detail in Cache-Control, file by file.

Dynamic HTML: carefully

A "My tickets" page differs per user. Cache it by mistake and one customer sees another customer's order, which is the worst bug you can ship. Personalized pages must be private, no-store, and the CDN should simply pass them through.

Public pages like the event page sit in between. You can cache them for seconds or minutes as long as you fetch live data like remaining seats separately.

APIs: usually no

Checkout, payments and any POST request can't be cached. For those, a CDN is just one more hop. If your API is slow, the bottleneck is a query or your code, not the distance to the user.

Where are your users?

If your origin and your users are on the same continent, the latency a CDN saves is modest; a few tens of milliseconds. The bigger win is offloading your server. If your audience is global, or your origin is far from most users, edge locations make a visible difference. Just remember a CDN is also a dependency: if its region has an outage, your static assets go with it.

Check three things before you buy

  1. Measure TTFB for your main page from a few locations. If it's above 800 ms, your server is the problem and a CDN will only hide it. Our TTFB guide helps you find the bottleneck.
  2. Look at the share of static traffic. If most of your bytes are images and JavaScript, a CDN pays off quickly.
  3. Audit your cache headers. Without correct headers, a CDN caches nothing, or caches the wrong things.

The ticketing team ended up putting only images and static assets behind the CDN, caching the event page for 30 seconds and loading seat availability with a separate request. Origin load dropped by half during the next big drop, and nobody saw anyone else's tickets.

Frequently asked questions

Join the discussion

No comments yet. Be the first to share your thoughts.