Next.js Migration
I led the migration of Byggdagboken's web platform from PHP and Angular.js to Next.js on AWS Lambda.
- Senior Software Engineer, client engineering lead
- 2024–2026
- Architecture
Route-level canary
A CloudFront Function sends this share of requests to the new Next.js client. The rest stays on the legacy monolith.
Context
Byggdagboken hired me to lead client engineering: the web client, the mobile apps, and the team building them. My first task was to replace the ageing web platform.
Problem
The web platform ran PHP on the server and Angular.js in the browser, backed by a set of Java microservices. It had become hard to scale, hard to release, and hard to change.
It could only scale by buying a bigger machine. PHP handled each request synchronously, holding a worker while it waited on backend services. Because every customer ran their own copy of the code on one server, adding machines was not an option.
One customer could slow down everyone else. All customers shared that server, so a heavy PDF export or bulk import from one customer degraded the platform for the rest.
Every release meant updating every customer. Each copy of the codebase had to be updated separately, which made releases slow and error-prone.
Development had stalled. Angular.js was no longer supported, there was no hot reloading, and business logic that belonged on the server had ended up in the browser. A previous attempt to fix the data layer with a shared backend-for-frontend had been abandoned halfway.
Decisions
Migrate one module at a time
The product was live, so a big-bang rewrite was out. I used the strangler fig pattern: the new client took over one module at a time while the monolith kept serving everything else.
The monolith. All web traffic went to the PHP and Angular.js application.
Gradual rollout. CloudFront sent a share of each migrated route's traffic to the new Next.js client, with the rest staying on the monolith.
Mobile backend-for-frontend. The native apps got their own Node.js service that gathers the data a screen needs into one response.
Standard sign-in. Sign-in moved to OAuth2 and OpenID Connect, with sessions held on the server.
Run one codebase for all customers
The new client runs a single codebase on AWS Lambda, served through CloudFront. One release now updates every customer at once, and Lambda adds capacity as traffic grows instead of depending on the size of one machine.
Move heavy work out of requests
PDF exports and bulk imports and exports now run through an AWS SQS queue in the background. A heavy job from one customer no longer slows the platform down for everyone else.
Let the Next.js server act as the web BFF
Rather than build a separate backend-for-frontend for the web, the Next.js server does the job itself. It calls the backend services, combines their responses, and applies business rules before anything reaches the browser. That moved logic out of the client and avoided another service to deploy and operate.
Other work at Byggdagboken
- I introduced new release routines; the releases that followed had zero major incidents.
- I automated the localization pipeline, which let us launch in 10 new languages.