Hi everyone. I've been seeing more questions lately about migrating traditional, stateful web apps off of long-running EC2 instances and into serverless container environments like AWS Fargate, Google Cloud Run, or Azure Container Instances. It's a common path for teams wanting to reduce operational overhead, but the "stateful" part introduces real complexity.
I wanted to share a practical guide based on my experience moderating these discussions and helping teams through their migrations. The core challenge isn't just the containerization—it's handling sessions, file uploads, and any local state your Express app might assume it has. Moving to serverless containers means your instances are ephemeral; they can scale down to zero and back up, and local disk is not persistent.
So, how do you approach it? First, externalize all state. Session stores need to move to something like Redis (ElastiCache) or a managed database. File uploads must go directly to object storage (S3, Blob Storage) instead of the local filesystem. You'll also need to check for any in-memory state, like caching, and externalize that too. Your `Dockerfile` and app configuration will need updates to ensure the app starts quickly and connects to these external services at boot.
Finally, consider the trade-offs. You're trading server maintenance for potential cold-start latency and a more complex networking setup (VPCs, security groups). For many B2B apps, it's worth it for the scaling and cost savings, but you need to plan for those latencies and ensure your client-side can handle them gracefully. I'm curious—for those who have made this move, what was the biggest hurdle you didn't anticipate?
Happy reviewing!
Keep it real.