What if you could migrate your frontend without telling anyone? We did.
Introduction
Can you migrate your entire frontend to a new stack without freezing development or triggering downtime?
That was the challenge we faced in 1000Farmacie when moving from a Next.js frontend to a fullstack Ruby on Rails setup.
But instead of treating this as a big-bang rewrite, we took a different approach: migrating the site route by route, while continuing our normal deploy rhythm (4–5 releases a day).
In this post, I’ll show how we pulled it off using AWS CloudFront, Application Load Balancer, Kubernetes, and a bit of Terraform and CDK8s automation — without disrupting our workflow or our users.
Our starting point
We started with a fairly standard architecture:
- Frontend: built in Next.js for historical reasons — we expected it to help with SEO and dynamic content, but in practice, those advantages never really materialized.
- Backend: Ruby on Rails, exposing APIs consumed by the frontend.
The decision to migrate the frontend to Rails was based on internal needs — simplifying the stack, improving integration between teams, a more efficient caching system, and making rendering more consistent. That said, this post isn’t about why we switched, but how we made it happen without breaking everything.
Managing traffic during a gradual migration
Rebuilding a live site while keeping it fully operational is never simple. In our case, the key challenge was managing traffic between the new Rails frontend and the legacy Next.js app.
Sure, Kubernetes gives you all kinds of ways to split and control traffic, but we wanted something that wouldn’t add unnecessary complexity or change our existing routing logic too much for a one time process.
Since we already had an AWS Application Load Balancer (ALB) in place, we decided to use it as our main traffic orchestrator — lightweight, flexible, and already battle-tested.
Testing in Production, without risk
We didn’t want this migration to interfere with our normal release flow. Every section we migrated needed to be tested first — ideally, in production — without exposing untested pages to all users.
That’s where header-based traffic splitting came in.
By routing traffic conditionally using ALB annotations and custom HTTP headers like X-fullstack-10, we could:
- deploy new sections as part of our standard pipeline;
- test them manually by passing headers from the browser or CLI;
- and slowly ramp them up to more users, without touching the app code.
Conditional routing with ALB Ingress
We implemented header-based routing using ALB Ingress annotations, allowing us to target specific percentages of traffic to the new frontend by simply adding a custom header.
Here’s how it worked in practice. For each traffic percentage (1%, 5%, 10%, etc.), we created a separate ALB action and condition, entirely driven by custom headers:
alb.ingress.kubernetes.io/actions.fullstack-10-routing: >
{
"type":"forward",
"forwardConfig":{
"targetGroups":[
{ "serviceName":"web-service", "servicePort":3000, "weight":10 },
{ "targetGroupArn":"...", "weight":90 }
],
"targetGroupStickinessConfig":{ "enabled":false }
}
}
alb.ingress.kubernetes.io/conditions.fullstack-10-routing: >
[
{
"field":"http-header",
"httpHeaderConfig":{
"httpHeaderName":"X-fullstack-10",
"values":["true"]
}
}
]
Thanks to CDK8s, generating this setup for multiple traffic splits took few lines of code:
for (const weight of [1, 5, 10, 20, 50, 100]) {
const feWeight = 100 - weight;
this.environment.ingressAnnotations[`alb.ingress.kubernetes.io/actions.fullstack-${weight}-routing`] = JSON.stringify({
type: "forward",
forwardConfig: {
targetGroups: [
{
serviceName: serviceWWW.serviceName,
servicePort: serviceWWW.servicePort,
weight: weight,
},
...(feWeight > 0 ? [{
targetGroupArn: FEtargetGroupArn,
weight: feWeight
}] : [])
],
targetGroupStickinessConfig: { enabled: false }
}
});
this.environment.ingressAnnotations[`alb.ingress.kubernetes.io/conditions.fullstack-${weight}-routing`] = JSON.stringify([
{
field: "http-header",
httpHeaderConfig: {
httpHeaderName: `X-fullstack-${weight}`,
values: ["true"]
}
}
]);
this.ingressServices.push({
hosts: [hostWWW],
serviceName: `fullstack-${weight}-routing`,
servicePort: -1
});
}
We could now test any page in production, just by adding a header. And once we were confident, we moved forward.
Dynamic CDN routing with CloudFront
CloudFront sits at the edge and was the first layer to decide where to send traffic.
To control that routing, we used Terraform to define which paths should go to which versions of the frontend — all dynamically.
Here’s what that looked like:
dynamic "ordered_cache_behavior" {
for_each = toset([
"/checkout/*", "/account/*", "/products/*"
])
content {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cache_policy_id = data.aws_cloudfront_cache_policy.default.id
cached_methods = ["GET", "HEAD"]
compress = true
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.default.id
path_pattern = ordered_cache_behavior.value
target_origin_id = "fullstack-100"
viewer_protocol_policy = "redirect-to-https"
}
}
The origin_id was also generated dynamically:
dynamic "origin" {
for_each = toset([
"fullstack-1",
"fullstack-5",
"fullstack-10",
"fullstack-20",
"fullstack-50",
"fullstack-100",
])
content {
connection_attempts = 3
connection_timeout = 10
domain_name = var.origins["backend"]
origin_id = origin.value
custom_origin_config {
http_port = 80
https_port = 443
origin_keepalive_timeout = 60
origin_protocol_policy = "https-only"
origin_read_timeout = 60
origin_ssl_protocols = ["TLSv1.2"]
}
custom_header {
name = format("X-%s", origin.value)
value = "true"
}
}
}
This way, CloudFront determined the target origin for each path, and the origin passed the corresponding header (e.g. X-fullstack-10) to the ALB, which handled the actual split.
Steady rollout, clean cutoff
This setup gave us full control with zero impact on developer velocity:
- New sections were released as part of our normal CI/CD process (4–5 deploys a day);
- Manual testing was easy — add the header and check behavior in production;
- Once stable, we added the path to CloudFront via Terraform to gradually shift traffic.
We repeated this process until all routes were hitting X-fullstack-100. At that point:
- we removed all
X-fullstack-*routing logic from ALB and CloudFront; - pointed everything directly to the new fullstack origin;
- and pulled the plug on our old Next.js frontend — clean and final.
Final thoughts
This wasn’t just a rewrite. It was a controlled evolution. No big bang, no frozen pipelines, no “dark launch.”
Instead of freezing development or rewriting everything behind a feature flag, we leaned on the infrastructure we already had.
With CloudFront, ALB, CDK8s and Terraform working together, we migrated the frontend without impacting development, without user disruption, and without losing our minds.
It worked — quietly.