NextJS App Not Performing Egress
audacity-london
PROOP

a month ago

Images being served staticly stopped being optimized and provided to user suddenly, no code changes. Everything works on local but on railway for last 20 mins I can see none of that images are being served. Thus, website is loading really slow (sometimes it just doesn't.)

I am deploying on other services as well to test in parallel (such as vercel, render etc) they all work fine.

$10 Bounty

2 Replies

Railway
BOT

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open Railway about 1 month ago


ahmeddakkak94
FREE

a month ago

This is a classic issue with Next.js Image Optimization on ephemeral file systems like Railway's. Since it works on Vercel and Render, the issue isn't your code; it's likely a bottleneck in the image processing pipeline or a permissions issue with the cache folder.

Here is a technical breakdown and 3 ways to fix this:

1. The "Persistent Cache" Strategy (Recommended)

By default, Railway wipes your local storage on every deploy/restart. If your .next/cache is lost, Next.js tries to re-optimize every image on the fly, hitting CPU/Egress limits and slowing down everything.

Fix: Create a Railway Volume (e.g., 1GB) and mount it to /app/.next/cache. This persists your optimized images across restarts and drastically reduces the load.

2. The sharp Dependency Check

Next.js uses a JS-based optimizer if sharp isn't found, which is extremely slow and memory-intensive.

Fix: Ensure sharp is explicitly installed in your package.json (npm install sharp). Also, check your Railway logs for "native-image-loader" warnings.

3. External Image Provider (The Pro Move)

If your traffic is high, offloading image optimization is better than using Railway's CPU.

Quick Fix: In next.config.js, set:

images: {

unoptimized: true,}

If this makes the site fast again, then you've confirmed that the Image Optimization engine is the culprit.

Summary: Most likely, your instance is hitting a 'cold start' on image generation because the cache is being wiped or is inaccessible. Try the Volume Mount first—it’s the most 'Railway-native' way to solve this.


ahmeddakkak94

This is a classic issue with Next.js Image Optimization on ephemeral file systems like Railway's. Since it works on Vercel and Render, the issue isn't your code; it's likely a bottleneck in the image processing pipeline or a permissions issue with the cache folder.Here is a technical breakdown and 3 ways to fix this:1. The "Persistent Cache" Strategy (Recommended)By default, Railway wipes your local storage on every deploy/restart. If your .next/cache is lost, Next.js tries to re-optimize every image on the fly, hitting CPU/Egress limits and slowing down everything.Fix: Create a Railway Volume (e.g., 1GB) and mount it to /app/.next/cache. This persists your optimized images across restarts and drastically reduces the load.2. The sharp Dependency CheckNext.js uses a JS-based optimizer if sharp isn't found, which is extremely slow and memory-intensive.Fix: Ensure sharp is explicitly installed in your package.json (npm install sharp). Also, check your Railway logs for "native-image-loader" warnings.3. External Image Provider (The Pro Move)If your traffic is high, offloading image optimization is better than using Railway's CPU.Quick Fix: In next.config.js, set:images: {unoptimized: true,}If this makes the site fast again, then you've confirmed that the Image Optimization engine is the culprit.Summary: Most likely, your instance is hitting a 'cold start' on image generation because the cache is being wiped or is inaccessible. Try the Volume Mount first—it’s the most 'Railway-native' way to solve this.

diogoribeirodev
FREETop 5% Contributor

a month ago

AI


Loading...