FlixTube in production
FlixTube runs on one laptop, but no customer can use it, nobody can see it fail, and it cannot grow. This chapter finishes the app and takes it to production: deploy it in safe steps, keep it healthy and reliable, scale it, and change it without breaking it.
key idea / coordinator service / good path in progress / watch out problem / failure neutral
In chapter 26 we built FlixTube's first services: video streaming over HTTP, packaged with Docker, booted with Docker Compose, with storage, MongoDB and RabbitMQ messaging. That left one problem open: the app runs only on a laptop, and production needs deployment, health and scale.
What turns a working prototype into an app people can rely on? By the end you can deploy FlixTube to Kubernetes by hand and automatically, keep it observable and fault tolerant, scale the team and the load, ship changes safely, and judge how far to take microservices at all.
Six services that all look alike
FlixTube can stream a video and record the view, but it cannot accept new videos and has no page to browse them. Each service also grew its own way, so switching from history to metadata means first hunting for its start script, tests and Dockerfile.
The finished app adds a gateway that serves the UI and an upload service. With the services from chapter 26, that makes six, plus a stand-in for development.
| Service | Purpose |
|---|---|
| Gateway | Entry point that serves the web UI and a REST API |
| Video streaming | Streams videos from storage to the viewer |
| Azure storage | Stores and retrieves videos in external cloud storage |
| History | Records the viewing history |
| Metadata | Records details about each video |
| Video upload | Orchestrates the upload of new videos |
| Mock storage | Development stand-in for Azure storage that uses the local disk |
Give every service the same folder layout and keep them all in one repository, with one deployment pipeline per service folder.
A monorepo used to defeat the point of microservices, because everything in it deployed together. A GitHub Actions workflow scoped to each subfolder fixes that: each service deploys on its own schedule.
One repository suits a small team and gets crowded as it grows (we split it later). And six services raise a question at once: which of them does the browser talk to?
One door in: the gateway and the request paths
Without a gateway the browser would call metadata for the video list, streaming to play, upload to add and history for past views. Every service would need a public address, and any internal change would break the web page.
One door at the edge of the cluster serves the UI and a REST API and forwards each request inward. Authentication belongs here too.
This is the gateway from chapter 12. If web, mobile and admin frontends need different things, each can get its own gateway on its own host name (backends for frontends).
The UI is deliberately plain: Express renders Handlebars templates on the server, with vanilla JavaScript and Tailwind CSS. The home route fetches the video list from metadata. A real product would probably use a single-page framework.
To play a video, the HTML video element requests a gateway route. Each of three services pipes the stream it receives into its own response, so the video moves byte by byte from cloud storage to the page. Upload is the mirror image: the body of an HTTP POST is piped from the upload page through the gateway and the upload service into storage.
While it streams, video streaming broadcasts a "video viewed" message over RabbitMQ and history records it. A new consumer can subscribe later without any change to streaming.
Every request now passes through the gateway, so its failures are everyone's. And both paths end in Azure storage, so every developer who tries upload needs a cloud account and a network.
Develop without the cloud: Compose, mocks and fixtures
Two developers test upload against the same Azure account and see each other's test videos. On a train, nothing works. Every manual test starts from whatever data is in the local MongoDB, so a bug seen once cannot be seen again.
The loop from chapter 26 still applies. Boot one service alone with npm install and npm start. Boot the whole app with docker compose up --build, wait for the gateway to print that it is online, then upload a video, watch it and check the history page.
Replace a whole service with a simpler one behind the same HTTP interface. Mock storage keeps videos on the local disk through a shared Docker volume, and no other service can tell.
Load a named set of realistic data before each test, manual check or demo, so every run starts from the same state.
Fixtures are JSON for static data or JavaScript for generated data. During Playwright tests a small REST API beside the app loads the fixture each test asks for.
Testing reuses chapter 14 and chapter 15, with one convention: npm test always runs the tests, whatever framework is behind it.
| Command and place | What runs | Scope |
|---|---|---|
npm test in the metadata folder | Jest unit tests, database library mocked | One service |
npm test at the repository root | Playwright, in three browsers | Whole running app |
npm run test:watch | Jest in live reload mode | While coding |
A mock can drift from the real service, so real storage must still be exercised somewhere. And all of this runs on a laptop: no customer has watched a video yet.
Get it to production in three steps
Production runs on Kubernetes, not Compose, as chapter 19 explained.
You write one GitHub Actions workflow that builds, pushes and deploys all six services to a cloud cluster. It fails. Is it the Kubernetes YAML, the registry login, or the pipeline? With everything new at once, you cannot tell.
Go from local Kubernetes to a manual production deploy to automatic deployment. If a step fails, go back to the easier one: you cannot automate what you cannot do by hand.
- Local. A script builds each image and applies each service's YAML to the Kubernetes bundled with Docker Desktop. The gateway appears on a NodePort at or above 30000. No registry is needed, and a delete script removes it all.
- Manual production. Log in to the private registry, set its address as an environment variable, and run the deploy script. It builds and pushes each image, fills in the templated YAML with
envsubst, and pipes the result tokubectl. - Automatic. One workflow per service, scoped to its folder, redeploys only what changed. Each can also be started by hand from the GitHub UI.
Shell scripts driven by environment variables do the work, so they run the same on a laptop and in the pipeline. MongoDB and RabbitMQ rarely change, so an infrastructure script deploys them once, by hand. A real product should use an external managed database.
The pipeline now holds secrets. And FlixTube runs where you cannot see it: when it breaks at 3 a.m., there is no terminal to look at.
See it, restart it, debug it
A healthy service is not crashing, not buggy and not starved of CPU or memory. Keeping it so starts with seeing it, as in chapter 17.
A viewer reports an empty home page. RabbitMQ restarted overnight, and the metadata service lost its connection. It is still running, but useless, and nobody knows where to look.
Services write normal events to standard output and errors to standard error. Docker or Kubernetes captures the streams, and a collector gathers them so you can search and alert.
| Where | How to read the logs |
|---|---|
| One service in development | Terminal output |
| Docker Compose | One merged stream; pipe it through tee to also save a file |
| Kubernetes | kubectl logs with the pod name; a pod can have several containers |
| A growing cluster | Install an aggregator; Kubernetes has none built in |
Log meaningful events and whether important operations succeeded. Never log secrets or personal details. Lean towards more logging: you cannot add it after the problem. Enterprise stacks (Fluentd, Elasticsearch and Kibana for logs; Prometheus and Grafana for metrics) are powerful but heavy, so do not rush to adopt them. Observability goes further: services emit rich telemetry (OpenTelemetry is the standard), and a tool such as Honeycomb follows one request across services to the span that failed.
Seeing a failure is half the fix. Exceptions, bad input and broken dependencies are unavoidable, so decide in advance how a service reacts.
On an unexpected error, log it, exit with a nonzero code and let Kubernetes start a fresh process. Probes let Kubernetes spot a service that is running but not healthy.
Use resume instead only where aborting loses work, such as uploads in progress. The metadata service did not crash, though. The readiness probe route says a service can take requests; the liveness probe route says it still works, and Kubernetes restarts it if not. Probes also fix chapter 26's start-up ordering problem and the case where RabbitMQ restarts later.
Some faults survive a restart. In a distributed app they hide among many processes, so debug with a repeatable routine:
| Symptom in production | First move |
|---|---|
| Service crashed | kubectl logs for the pod, and for the previous instance |
| Pod in error or restarting | kubectl get pods for status and restart count |
| Image pull errors | Cluster cannot reach the registry: check the connection and image name |
| Cannot find the problem | Experiment in production only if you cannot reproduce it elsewhere |
Restarts can hide a recurring bug, and a restart takes time: while the only instance is down, every user who needs it gets an error.
Keep serving while parts fail
Restarting repairs a failure afterwards. Users need the app to work while it happens. Chapter 18 has the full patterns; here is FlixTube's minimum.
A corrupt file crashes the single upload instance. The gateway calls upload with Axios, which waits forever by default, so gateway requests pile up and the home page hangs too. One bad file has taken down the site.
Start inside each service with defensive programming (expect bad input, hidden bugs and unreliable dependencies) and defensive testing that attacks the code to check that errors are reported and recovered from. Protect source data above all: an uploaded video matters more than a thumbnail you can regenerate. Automate backups, practice restoring, keep capture code small and tested, and never write code that overwrites or deletes source data.
Run at least three instances behind a load balancer, so others serve while Kubernetes restarts a failed one. It is one field in the deployment YAML: replicas: 3.
Still investigate every failure. And replicas do not help when every one of them meets the same bad file.
Contain a failure where it happens. The gateway catches upload's error, says upload is unavailable, and keeps serving the rest. This is the bulkhead idea: lose one feature, keep the app.
A timeout and a retry stop the gateway hanging on upload. A job queue stores heavy work, such as a thumbnail per video, in a database-backed queue: workers pull one job when free, jobs survive a crash and failed jobs run again, spreading load over time. A circuit breaker already knows a service is failing, so it fails at once without waiting.
Three replicas of everything triple the compute bill, and every fallback is code to test. FlixTube now survives failure, but one person built it. The next problems come from growth.
Scale the team and the load
Three developers join. Every push to main deploys straight to customers, and two developers keep breaking each other's work in the shared repository. A month later a video goes viral, and video streaming runs at full CPU while the other services idle.
Service boundaries are natural seams for splitting the work: each team owns its services from development to production (chapter 25).
Split the monorepo into a repository per service plus one for infrastructure, and give each environment a branch whose merges deploy to it.
A meta-repo (the meta tool and a .meta file) ties the repositories back into one virtual repository, so cloning and running everything feels like a monorepo again. Each team can keep one for its own services.
Each environment comes from the Terraform code of chapter 19, parameterized by environment name, with its state in cloud storage. A push to the development branch runs the CI tests from chapter 21 and deploys to development. Shorter gaps between merges mean fewer integration surprises. A separate configuration repository can also record which version of each service is deployed: the service pipeline publishes an image, and a change to that repository deploys it.
Now the viral video. Microservices let you add capacity to one part, as chapter 22 showed.
Find the bottleneck in the Kubernetes dashboard or cloud portal, then use the lightest fix. Most are a one-line change in Terraform or YAML.
Raise the VM size or the node count of the cluster, or raise the streaming service's replicas, the same field that gave redundancy. Elastic scaling does it automatically: the cluster autoscaler grows the node pool, and a horizontal pod autoscaler grows one service, each between a minimum and a maximum, so you pay only for the load you have. For data, keep one database per service so no shared database becomes the bottleneck; later spread them over more servers, then shard huge data sets.
More repositories, branches and environments mean more pipelines to maintain. And every scaling change is itself a change to production that can break the cluster.
Change it without breaking it
A developer merges a gateway change that crashes at start-up. The pipeline deploys it to every gateway pod, and every viewer sees an error. The same week, someone finds MongoDB and RabbitMQ, opened during early experiments, still reachable from the internet.
Catch a bad change as early, and as cheaply, as possible: in a pull request, in a test environment, during rollout, or by switching a whole environment.
A rolling update replaces replicas one by one and moves on only when the new one passes its readiness probe. The broken gateway would stop at its first pod while the old pods keep serving, and you roll back. maxSurge and maxUnavailable cap how many extra and missing pods are allowed at once.
For risky infrastructure changes, such as the scaling changes above, use blue-green deployment: build a second environment from Terraform, test it, repoint DNS, and point it back if it misbehaves. A stateless cluster makes this safe.
The open ports call for basic security (chapter 16 has the patterns).
Expose only the gateway. Add authentication there and HTTPS. Keep passwords, tokens and API keys in GitHub secrets, Kubernetes secrets or a tool such as Vault.
Think like an attacker: how would someone break this? Keep it simple; simple systems hide fewer flaws.
Each layer slows the path to customers a little, and blue-green briefly doubles the infrastructure. All of it also assumed FlixTube was built as microservices from day one. Most teams start elsewhere.
Starting from a monolith instead
A team with a large monolith, like FTGO in the rest of this course, decides to rewrite it all as microservices at once. Months later nothing new has shipped, the rewrite is half done, and the old system still needs care.
Convert the way FlixTube was built: small tested steps that keep the system working while features ship. First ask whether you need microservices at all.
Chapter 23 showed the strangler approach for FTGO. The practical sequence:
Carve along natural seams, components that already look like services; without them, refactor inside the monolith first, under tests. Extract first what changes most or gains most in speed or scale. Returns diminish: later extractions bring less, and services that are too small cost more than they give. It is fine to stop.
The hybrid, a monolith with a few helper services for jobs like thumbnails, is a sensible default when unsure. If you go all the way, start cheaply:
| Microservices on a budget |
|---|
| A monorepo with one CD pipeline per service; a meta-repo after splitting |
| One database server, with one database per service |
| A one-VM cluster, one instance per service, simple pipelines |
| External file storage and database, so the cluster stays stateless |
| Without automated tests, a fast scripted boot with Compose and fixtures; automate deployment early |
Two architectures run side by side, often for years, and automation must exist before the first extraction pays off.
Practices in this chapter
| Practice | Problem it solves | What it costs |
|---|---|---|
| Shared layout, monorepo, pipeline per service | Services organized differently; joint deploys | Crowded as the team grows |
| API gateway | The browser would need every service | One more hop on every request |
| Mock service and fixtures | Development needs the cloud; tests start from unknown data | Mocks drift; fixtures to maintain |
| Deploy in stages | A failing pipeline with too many new parts | Secrets in the pipeline |
| Logs, observability, probes | Unseen and half-broken services | Tooling; restarts can hide bugs |
| Replication and fault isolation | One failure takes down a feature or the site | Compute; fallbacks to test |
| Timeout, retry, job queue, circuit breaker | Hanging calls and bursts of heavy work | Tuning; delayed work |
| Repository per service, environment per branch | A growing team ships untested, clashing code | More repositories and pipelines |
| Measured, elastic scaling | One service overloaded by demand | Scaling changes are risky changes |
| Rolling update, blue-green, small attack surface | Bad releases and exposed internals hit everyone | Slower rollouts; a second environment |
| Incremental refactoring, hybrid | A big-bang rewrite stalls delivery | Two architectures for a long time |
Recap
- The finished FlixTube is six services behind one gateway, with one layout in one monorepo, and mocks and fixtures keep development fast and independent.
- Deployment goes from local Kubernetes to a manual deploy to one CD pipeline per service, so each failure has few possible causes.
- Health needs logs in one place, abort-and-restart with readiness and liveness probes, and a repeatable debugging routine.
- Reliability comes from defensive code, protected source data, replicas, fault isolation, and timeouts, retries, job queues and circuit breakers.
- Growth needs repositories per service, environments per branch, measured scaling, rolling updates, blue-green deployment and only the gateway exposed.
- A monolith is converted in small tested steps along natural seams, and stopping at a hybrid is a fine result.
Quick check
Show answer
Upload fails, and because Axios waits forever by default, gateway requests pile up until other pages hang too. Set a timeout, and let the gateway catch the error and report that upload is unavailable while serving everything else (fault isolation). Several replicas of upload keep it available while Kubernetes restarts the crashed one.
Show answer
A rolling update waits for readiness, so it stops after the first replica. The old replicas keep serving, and you debug and roll back.
Show answer
Early on you rarely need redundancy or extra performance, and it costs little. A stateless cluster with a database per service can later scale by changing replica and node counts, without a redesign.
This is the end of the course. You followed FTGO from monolithic hell to dozens of services and built FlixTube from one service to production. What stays open is your own system: which patterns it needs, and in what order. The pattern map lists every pattern with the problem it solves, so you can start from your own pain.