Skip to content
sadat.
All writing
NOTES FROM THE WORKBENCH

How I Debugged My Next.js Portfolio Deployment on Railway

A hands-on debugging story covering Next.js rendering, Payload CMS migrations, PostgreSQL, Railway deployment, and portfolio performance optimization.

Next.js and Payload CMS deployment debugging

Building a portfolio is one thing. Getting it to run reliably in production is another.

Recently, while deploying my developer portfolio, I encountered several issues involving Next.js, Payload CMS, PostgreSQL, and Railway. What initially appeared to be a simple deployment problem turned into a valuable lesson about database migrations, server-side rendering, and application performance.

Here's what happened and what I learned.

The Tech Stack

My portfolio uses:

Next.js 16 for the frontend and server-side rendering

Payload CMS for managing blog content

PostgreSQL for persistent data

Railway for application and database hosting

This setup allows me to manage content through an admin dashboard while maintaining a customized frontend.

Problem 1: Successful Build, Broken Application

One of the most confusing situations was seeing a successful production build while parts of the website failed to work.

The homepage loaded, but database-dependent routes such as /posts and /admin were problematic.

I learned an important distinction:

A successful build does not guarantee a healthy application at runtime.

For the blog listing, I also reviewed when Payload was initialized. Using Next.js's connection() API allowed me to defer the database-dependent operation until a request arrived rather than performing it during prerendering.

Problem 2: PostgreSQL Migration Conflicts

The most important discovery came from Railway's deployment logs.

Payload detected that development-mode schema changes had previously been pushed to the database. When production migrations started, it requested confirmation because proceeding could cause data loss.

I inspected the migration history and found an initial migration recorded as completed alongside a development-mode marker.

After reviewing the situation and taking precautions, I cleaned up the migration metadata and restarted the application.

The database-dependent routes began working again.

My biggest lesson: Development schema synchronization and production migrations should be managed carefully, preferably using separate development and production databases.

Problem 3: Unexpected Memory and Network Usage

Initially, my portfolio application was using approximately 450 MB of memory despite having very little traffic.

I investigated the deployment logs, reviewed the application configuration, and optimized several large photographs.

Three gallery images originally totaled approximately 31 MB. After optimization, their combined size was reduced to about 1 MB while keeping them usable in the portfolio.

After resolving the deployment issue and applying improvements, Railway metrics showed application memory around 136 MB, with PostgreSQL using approximately 62 MB.

I cannot attribute the entire memory reduction to a single change, but the experience reinforced the importance of measuring application behavior rather than optimizing blindly.

What I Learned

This debugging experience gave me practical exposure to several engineering concepts:

Build-time rendering versus request-time rendering.

PostgreSQL connections and database migration history.

Environment variables across local and production environments.

Production logging and troubleshooting.

Image optimization and server resource monitoring.

Perhaps the most valuable lesson was that debugging requires observing the system, forming hypotheses, and testing them systematically.

What's Next?

I'm continuing to improve my portfolio while exploring backend engineering, database design, system architecture, and deployment practices.

I'll use this blog to document what I build, the problems I encounter, and the lessons I learn along the way.

GitHub: https://github.com/rafi1210

Portfolio: https://sadatahmedrafi.xyz/


How I Debugged My Next.js Portfolio Deployment on Railway | Payload Website Template | Sadat Ahmed Rafi