Site Search for Web Apps: Postgres vs Elasticsearch vs Algolia
Choosing search for your web app? Compare Postgres full-text search, Elasticsearch and Algolia on cost, relevance, effort and when to outsource the build.
A practical guide to web application caching strategies: browser, CDN, application and database layers, plus invalidation rules and common mistakes.
Caching is the cheapest way to make a web application faster and to cut hosting costs. It is also one of the easiest ways to ship stale data, leak private content or create bugs that nobody can reproduce. For a CTO, founder or product manager, the goal is not to cache everything. It is to cache the right things, at the right layer, with a clear rule for when they expire.
This guide walks through the main caching layers, how to choose between them and what to ask your development team before caching goes live.
A request can be answered from several places before it ever reaches your database. Each layer trades freshness for speed.
| Layer | What it stores | Typical use | Main risk |
|---|---|---|---|
| Browser cache | Static files, API responses | Images, CSS, JavaScript | Users keep old files after a release |
| CDN / edge cache | Pages and assets near the user | Marketing pages, assets, public APIs | Serving private or outdated content |
| Application cache | Computed results in memory (for example Redis) | Expensive queries, sessions, rate limits | Inconsistent data between servers |
| Database cache | Query plans and hot data pages | Repeated reads | Hides slow queries rather than fixing them |
Start at the outer layers. A response served from the browser costs you nothing. A response served from a CDN costs very little. Only the requests that miss both should reach your servers.
Most of the benefit comes from setting HTTP headers correctly.
For static assets, use fingerprinted file names such as app.3f9c2a.js and give them a long lifetime. When the file changes, the name changes, so you never need to invalidate anything. For HTML pages, use short lifetimes or revalidation so that a release reaches users quickly.
When a page depends on expensive work, such as a report, a search or a third-party API call, cache the result in memory.
Common patterns:
Always set an expiry. A cache without a TTL is a second database that nobody remembers to clean.
The old joke says there are two hard problems in computing, and cache invalidation is one of them. It is hard because the cache and the source of truth are separate systems that can disagree.
Practical ways to keep it manageable:
product:42:v7) means old entries simply stop being used.Some content needs extra care:
Vary header).Caching choices are closely linked to how pages are rendered. Static generation pairs naturally with long CDN lifetimes, while server-rendered pages need shorter lifetimes or revalidation. Our guide to SSR vs SSG vs CSR explains the trade-offs. Caching also directly improves load metrics, which we cover in our Core Web Vitals guide.
Ask your team to confirm each item before release:
Do not guess. Record response times and server load before adding a cache, then compare afterwards. If the hit rate is low, the cache adds complexity without benefit. If a slow query is the real problem, fix the query first and cache second.
Good caching design is a mix of HTTP knowledge, infrastructure and careful testing. If you are planning a new product or want to speed up an existing one, our web development services cover architecture, performance work and delivery by a dedicated team in Chennai. To talk through your requirements, contact us and we will respond with practical next steps.
Choosing search for your web app? Compare Postgres full-text search, Elasticsearch and Algolia on cost, relevance, effort and when to outsource the build.
WebSockets vs SSE vs polling: how to choose the right approach for live dashboards, chat and notifications, with cost, scaling and testing trade-offs.
How to integrate a payment gateway into a web or mobile app: choosing a provider, hosted vs custom checkout, webhooks, security and testing before launch.
Tell us about your platform, your product idea or the systems you want to modernise. Someone from our Chennai engineering team will get back to you personally.