Contents (7)
- [Blog Introduction] DB, Backend, Frontend, and App Compatibility in Zero-Downtime Deployment
- 1. Shared DB ↔ Blue/Green Backend: Expand & Contract
- Example. Converting Post Table to Multilingual Table (Expand + Dual-Write)
- 2. Backend ↔ Web Frontend: Backward Compatibility + Deployment Order + Key Fallback
- 3. Separation of code distribution and feature openness: Default OFF feature flag
- 4. Web Front-end ↔ Mobile App: Handling the Longest Interval
- Summary: Four-tier compatibility standards
[Blog Introduction] DB, Backend, Frontend, and App Compatibility in Zero-Downtime Deployment
In the previous post , I eliminated 502 errors during backend deployment by running blue and green containers alternately.
However, as I added and modified features later, this became an issue the moment different versions briefly coexisted . This blog's DB, backend (GCP Blue/Green), web frontend, and mobile app are deployed at different times.
How can I prevent
blue, which is still running, from breaking whilegreenis changing the DB schema?The deployment timing of the frontend and backend do not align perfectly. What happens when an older frontend meets a new backend (or vice versa)?
What happens if a user of the old version of the app who hasn't updated the App Store enters the newly released web screen?
In this post, I plan to summarize how much compatibility is guaranteed via code and how parts were released in the order of deployment .
1. Shared DB ↔ Blue/Green Backend: Expand & Contract
Flyway is attached to the backend for schema versioning, so migrations run automatically when a new container ( green ) starts. The problem is that even though there is only one DB, it switches the DB before green even receives traffic .
sequenceDiagram
autonumber
participant User as "Visitor"
participant Caddy as "Caddy"
participant Blue as "Blue (Old)"
participant Green as "Green (New)"
participant DB as "Cloud SQL (Shared)"
%% 1. Normal cycle before deployment
User->>Caddy: Real-time requests
Caddy->>Blue: Request forwarding
Blue->>DB: Read in the existing way/write
DB-->>Blue: Return result
Blue-->>Caddy: Return response
Caddy-->>User: Response complete
%% 2. Start Green and Change DB Schema
Green->>DB: Run migration at startup (DB change)
%% 3. Transitional Cycle (Blue handles until completion)
Note over Blue,DB: While Green waits for the health check (~25 seconds, permanent if it fails), Blue must continue to operate over the changed DB.
User->>Caddy: Real-time requests (Before conversion)
Caddy->>Blue: Request forwarding
Blue->>DB: Execute existing query (Backward compatibility is essential!)
DB-->>Blue: Return normal result
Blue-->>Caddy: Return response
Caddy-->>User: Response complete (BlueHandle it to the end)
%% 4. Health Check Pass and Traffic Switching
Green-->>Caddy: Healthcheck 200
Note over Caddy,Green: Switch routing targets (Blue ➔ Green)
%% 5. New request cycle after transition (handled by Green)
User->>Caddy: New real-time request (After conversion)
Caddy->>Green: Request forwarding
Green->>DB: Execute new query
DB-->>Green: Return result
Green-->>Caddy: Return response
Caddy-->>User: Response complete
%% 6. Termination of old version
Caddy--xBlue: endThe section where the shared DB changes first during Blue/Green deployment
Until green passes the health check (and continues thereafter if green fails to boot and the deployment is canceled), blue must read and stack data on the changed DB using the existing method.
Therefore, when changing the DB structure, we do not overhaul it all at once but divide the deployment into Expand & Contract sequences. Our principle is not to delete or rename the old schema until the existing server is completely taken down.
flowchart LR
S1["1. Expand (Add new schema)"] --> S2["2. Dual-Write & Backfill"]
S2 --> S3["3. Switch (Complete termination of old version)"]
S3 --> S4["4. Contract (Clean up old schema in the next deployment)"]Expand & Contract Zero-downtime schema transition
Example. Converting Post Table to Multilingual Table (Expand + Dual-Write)
Originally, the article title, body, and summary were all in article_mst , but to support four languages, we had to move them to the article_translation table. If we had simply deleted the existing columns and moved them, the blue query would have broken immediately upon deployment, and a rollback would have been impossible.
So, I performed two processes for compatibility.
Expand + Backfill (
V2) : The existing columns ofarticle_mstwere kept as they were, onlyarticle_translationwas newly created, and the existing Korean text was idempotently backfilled intoON CONFLICT DO NOTHING.Dual-Write (
ArticleService) : The new server (green) writes to botharticle_mstandarticle_translation(ko)simultaneously when writing, editing, or publishing a post.
// While the new server (green) is starting, it records in both the old table and the new table.Article saved = articleRepository.save(article); // Existing article_mstarticleTranslationRepository.save(buildKoTranslation(saved, published)); // New article_translationThanks to this, blue continues to work in the existing way without knowing anything about the new table during the transition, and even if a bug occurs in green and you revert to blue , the posts written in between remain in article_mst , allowing you to roll back without data loss. You just need to clean up (contract) the old columns in the next deployment after the frontend transition is completely finished.
2. Backend ↔ Web Frontend: Backward Compatibility + Deployment Order + Key Fallback
Since the backend and frontend are deployed to different repositories and pipelines, they are not deployed together at the exact same time. Therefore, there are two potential issues.
Old Frontend -> New Backend Reference
New Front-end -> Old Back-end Reference
So, we devised a strategy to prevent each of the problems from occurring.
Always make the backend backward compatible with the old frontend .
All multilingual
?lang=parameters becomerequired = false(if not sent, the response iskoas before)Keep the existing fields of the response DTO and add only the new fields
Push notifications, category name changes, and translation management have all been separated into a new endpoint.
Since it is costly to implement bidirectional fallback for all new APIs , the basic principle is backend deployment first → frontend deployment later .
I thought the two strategies above were the least likely to complicate the code. Of course, since it is a blog service with almost no users , taking a brief maintenance period to handle it would actually be the cleanest approach!! I don't even expect these methods to always work with 100% uninterrupted operation. However, I decided to give it a try because, as a personal blog, I could approach it with peace of mind .
3. Separation of code distribution and feature openness: Default OFF feature flag
For features requiring external API keys or new infrastructure, we completely separated the code deployment time and the feature enabling time .
If the switch is set to the default false , you can securely deploy the schema and code first. Then, enable the feature once both the frontend and backend are securely deployed.
4. Web Front-end ↔ Mobile App: Handling the Longest Interval
I learned that while the deployment difference between backend and web frontend is at most a few minutes, mobile apps can have old and new versions coexist for weeks due to store reviews and delays in user updates . (I’ve also experienced not updating an app for a long time...)
The situation I envisioned regarding this issue is that when attaching push notifications, WebView apps require a bridge to receive the FCM token from the native source and pass it to the web, but older versions of the app that haven't been updated lack that bridge.
The WebView inserts window.__carrotAppPush = {version: 1, platform} before loading the page. The web sees this object and requests a token from the app push bridge.
window.ReactNativeWebView exists but window.__carrotAppPush does not. The web detects this state and safely branches to the "App update required" notification screen instead of an error.
So, instead of using the App, I made it possible to resolve the issue through variables registered in the window on the Web. I solved it by inducing an update through a method where the Web checks whether it was loaded via the App's WebView.
Summary: Four-tier compatibility standards
boundary | Coexistence time | Solution |
|---|---|---|
DB ↔ Blue/Green Backend | ~25 seconds (permanent on failure) | Expand & Contract, Dual-Write, |
Backend ↔ Web Frontend | A few minutes | Backend backward compatibility (preserving optional parameters and existing fields) + backend pre-distribution |
Code Distribution ↔ Feature Opening | Until setup is complete | Control when features are unlocked using the default feature flag |
Web Front-end ↔ Mobile App | Several days to several weeks or more | Branching the old version app from the web based on |
If the previous post covered how Caddy Blue/Green implemented zero-downtime deployment through traffic switching, this time I will explain how to implement zero-downtime deployment so that the DB, backend, frontend, and app do not break even when deployed separately across different services. The goal of zero-downtime deployment is to ensure existing services operate seamlessly, but in reality, interruptions are inevitable if there is a lack of consistency between versions, right?
This time, for the first time, I divided it by layer to ensure compatibility even if the version changes. It gave me a lot of insight into how to consider compatibility when writing code.
