:whale: Next.js app with 2 pods sharing cache on redis
TypeScript
156
135 commits
updated Apr 23, 2026
Next.js web application with 2 pods sharing cache.
[!NOTE] You can also check the other branches for Next.js 14 (
main-14), Next.js 15 (main-15) or Redis Strings (redis-strings) as there are variants that may also be useful to you.
I created the Docker image following the example in:
https://github.com/vercel/next.js/tree/canary/examples/with-docker
I configured the output: "standalone" property in next-config.ts.
More info at:
https://nextjs.org/docs/app/getting-started/deploying#docker
I use ValKey to cache values and ensure consistency across all pods.
I installed custom handler using
npm install @mrjasonroy/cache-components-cache-handler:
More info at:
https://github.com/mrjasonroy/cache-components-cache-handler
I added cache-handler.mjs and configured the cacheHandlers property in
next.config.ts.
cacheComponents: true,
cacheHandlers: {
default: require.resolve("./cache-handler.mjs"),
remote: require.resolve("./cache-handler.mjs"),
},
cacheMaxMemorySize: 0, // disable default in-memory caching
Additionally, I enabled cacheComponents: true to cache the rendered components.
I followed this example and the same pages to validate the cache using use cache,
cacheTag, cacheLife, updateTag and revalidatePath.
[!WARNING] Only Next.js 16 + cacheComponents supports these features.
[!WARNING] CacheHandlers (with S) is different than CacheHandler (without S).
More info at:
https://nextjs.org/docs/app/guides/self-hosting
https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandlers
https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath
In the k8s folder, there are all the Kubernetes manifests to create two pods with
the Next.js web application and one pod with a Redis server.
Run in dev mode with npm run dev.
Run in Docker using Docker Compose with
docker compose -f "compose.yaml" up -d --build.
Run in Kubernetes:
docker build -t nextjs-docker . to create the Docker image.kubectl apply -f k8s/configmaps/nextjs.yaml.kubectl apply -f k8s/deployments/nextjs.yaml.kubectl apply -f k8s/deployments/redis.yaml.kubectl apply -f k8s/services/nextjs.yaml.kubectl apply -f k8s/services/redis.yaml.http://localhost:3000.[!NOTE] You can use this option to deploy your Docker image on your VPS.
134 commits
1 commits
TypeScript
91.3%
CSS
5.0%
Dockerfile
2.7%
:whale: Next.js app with 2 pods sharing cache on redis
TypeScript
156
135 commits
updated Apr 23, 2026
Next.js web application with 2 pods sharing cache.
[!NOTE] You can also check the other branches for Next.js 14 (
main-14), Next.js 15 (main-15) or Redis Strings (redis-strings) as there are variants that may also be useful to you.
I created the Docker image following the example in:
https://github.com/vercel/next.js/tree/canary/examples/with-docker
I configured the output: "standalone" property in next-config.ts.
More info at:
https://nextjs.org/docs/app/getting-started/deploying#docker
I use ValKey to cache values and ensure consistency across all pods.
I installed custom handler using
npm install @mrjasonroy/cache-components-cache-handler:
More info at:
https://github.com/mrjasonroy/cache-components-cache-handler
I added cache-handler.mjs and configured the cacheHandlers property in
next.config.ts.
cacheComponents: true,
cacheHandlers: {
default: require.resolve("./cache-handler.mjs"),
remote: require.resolve("./cache-handler.mjs"),
},
cacheMaxMemorySize: 0, // disable default in-memory caching
Additionally, I enabled cacheComponents: true to cache the rendered components.
I followed this example and the same pages to validate the cache using use cache,
cacheTag, cacheLife, updateTag and revalidatePath.
[!WARNING] Only Next.js 16 + cacheComponents supports these features.
[!WARNING] CacheHandlers (with S) is different than CacheHandler (without S).
More info at:
https://nextjs.org/docs/app/guides/self-hosting
https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheHandlers
https://nextjs.org/docs/app/api-reference/config/next-config-js/incrementalCacheHandlerPath
In the k8s folder, there are all the Kubernetes manifests to create two pods with
the Next.js web application and one pod with a Redis server.
Run in dev mode with npm run dev.
Run in Docker using Docker Compose with
docker compose -f "compose.yaml" up -d --build.
Run in Kubernetes:
docker build -t nextjs-docker . to create the Docker image.kubectl apply -f k8s/configmaps/nextjs.yaml.kubectl apply -f k8s/deployments/nextjs.yaml.kubectl apply -f k8s/deployments/redis.yaml.kubectl apply -f k8s/services/nextjs.yaml.kubectl apply -f k8s/services/redis.yaml.http://localhost:3000.[!NOTE] You can use this option to deploy your Docker image on your VPS.
134 commits
1 commits
TypeScript
91.3%
CSS
5.0%
Dockerfile
2.7%