Architecture of an AI Subtitle Generator: Five Pieces and One Upload Traced End to End
An AI subtitle generator takes an audio or video file and gives back an SRT. Meet its five pieces (React, an identity provider, a Python API, a Celery worker running Whisper, and S3) and follow one upload through all of them.
What you will learn
- Name the five pieces of a long-job AI app and what each one does
- Explain why Whisper runs in a Celery worker and not inside the API request
- Trace one upload from the browser to S3, the queue, the worker and back
- See why a shared API contract lets FastAPI, Flask or Django sit behind the same React app
Before you start
- Basic Python
- What an HTTP API is
Here's the job in one line: you drop in an audio or video file, and you get a subtitle file back, an SRT. Doing that by hand means listening, typing every line and setting a time for each one. For one long video that's hours of work.
The model doing the work is Whisper, an open model from OpenAI that runs on your own hardware. It isn't heavy, so a normal machine can run it, and on a GPU it's quick. But even on a GPU a long file takes time, and a web request can't sit there and wait. That makes this a good first use case: it needs background processing, with a queue and a worker, which is how real applications handle long jobs.
This article has no code. It's the picture you keep in your head while the app gets built.
A recording studio with one door
Picture a small recording studio. It has one door, and nobody gets in without signing in there. That door is the identity provider. Inside, the reception is the React front end, the part the visitor sees. The mixing desk is the backend: it takes each request and decides what happens next. The tape machine in the back is the Celery worker running Whisper. It does the heavy lifting and takes its time. And the vault is S3, where every file is kept.
You can swap the mixing desk for another one, and the door, the tape machine and the vault don't care.
The five pieces with their real names
- React app. It loads in the browser. The user signs in, uploads a file and later downloads the subtitles here.
- Identity provider. The user signs in with a username and password, or with Google, and the provider hands back a token.
- Python API. FastAPI, Flask or Django. It only answers requests that carry a valid token.
- Celery worker with Redis. Long jobs don't run inside the API. They go on a queue that Redis holds, and Celery runs the worker that takes jobs from it. The worker runs Whisper, turns speech into timed text and writes the SRT.
- S3. It keeps the uploaded file and the finished SRT behind the sign in, so only the user who uploaded a file can download it.
Why a queue?
Say three people upload a file at the same time. The API doesn't transcribe anything itself. It saves the file, puts a job on the queue and answers right away with a job number, so nobody's browser is stuck waiting for minutes.
The worker takes the jobs one by one. There's usually one GPU, and Whisper uses it for one transcription at a time. The other jobs wait their turn in the queue, and nothing gets lost. That's the work Redis and Celery do here. How Celery works is in Celery and Redis for background tasks.
One upload, step by step
- The user picks a file and clicks Upload.
- The file rides from the browser to the API, with the token attached.
- The API checks the token and stores the file in S3.
- It puts a job on the queue, and the browser gets the job number back.
- The worker picks up the job, fetches the file and hands it to Whisper. If the upload was a video, only its audio goes to Whisper.
- Whisper turns the speech into text with times, and the worker saves the SRT into S3.
- Meanwhile the browser asks for the job status every couple of seconds: queued, then processing, then done. That's called polling.
- When the status says done, the SRT comes back from S3 and the user can download it.
Step 4 returns at once. Everything after it happens on the worker's clock, not the user's.
Two identity providers, one job
The door is built twice. First with Keycloak, a popular open source identity provider you run yourself, here in Docker on your own machine. A lot of teams use it, so it's good to know. Later the app moves to Cognito, the identity provider AWS runs for you, which can also offer Google sign in.
Both do the same job. The user signs in, gets a token, and the backend checks that token on every request. So when Keycloak is swapped for Cognito, the queue, the worker and S3 stay exactly as they are. The details are in the identity provider flow with Keycloak and Cognito vs Keycloak.
Three backends, one contract
The mixing desk can be FastAPI, Flask or Django. The front end is the same React app for all three. That works because of the API contract: every backend has the same routes, takes the same requests and sends back the same JSON. The React app doesn't know or care which backend is behind it, and that's a good habit for any project you build.
Where it ends up
First the app runs on your own machine. Then it moves to AWS, onto an EC2 server, so anyone with the link can open it and sign in. That server is a small one with no GPU, so it doesn't cost much. Whisper runs there on the CPU, which is slower, but it keeps the bill down. The deployment is in running the app on one EC2 instance.
Most of the code is built with an AI coding agent from clear prompts. Your job is to check the structure and each component. When you know what each box does, you can tell whether the code you get is right.
Quick recap
| Piece | Job |
|---|---|
| React app | Sign in, upload, poll the status, download |
| Identity provider | Signs the user in and issues a token |
| Python API | Checks the token, stores the file, queues the job, answers at once |
| Redis + Celery worker | Holds the jobs and runs Whisper one at a time |
| S3 | Keeps the upload and the SRT, private to the user |
Try it yourself
Draw the five boxes from memory, and trace one upload through them with the token at every step.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
