The Latency Problem
Marketing homepages are the first point of contact for users. If a landing page takes more than 500ms to load, conversion rates drop by up to 50%. However, driving homepage slots dynamically from a Postgres database introduces network hops and query execution costs.
Next.js L1 + Redis L2 Caching
To solve this, we implemented a dual-layer caching pipeline: 1. L1 Cache (Next.js Data Cache): In-memory cache on the edge node rendering the page. 2. L2 Cache (Redis Cluster): Distributed cache storing serialized query outputs.
When a database slot changes, we publish an invalidation tag. This clears the L1 cache across edge routers and evicts the keys in Redis, ensuring updates are visible globally under 100ms while serving subsequent requests in under 2ms.