0%
System requirements
Functional
Capacity estimation
Traffic
API design
Translation Endpoint
Database design
Redis — Translation Cache
High-level design
Request flows
Online Translation Flow
Detailed component design
Translation Engine Pipeline (GATE)
Tradeoffs
Third-Party vs Self-Hosted Translation
Failure scenarios
Future improvements
Speech-to-Text Translation
System requirements
Functional
Capacity estimation
Traffic
API design
Translation Endpoint
Database design
Redis — Translation Cache
High-level design
Request flows
Online Translation Flow
Detailed component design
Translation Engine Pipeline (GATE)
Tradeoffs
Third-Party vs Self-Hosted Translation
Failure scenarios
Future improvements
Speech-to-Text Translation
A language translation service takes text in one language and produces equivalent text in another. Google Translate handles over 100 billion words per day across 130+ languages. The core challenge is not just translating accurately — it is doing so at massive scale with low latency, while supporting users who may have no network connection at all.
The numbers for a translation service look different from a typical CRUD application because the bottleneck is not database I/O — it is ML model inference on GPUs. Every estimate below traces back to one question: how many translation engine instances do we need?
The API needs to support three core operations: single translation, batch translation, and language detection. Every endpoint requires authentication via API key or JWT token in the Authorization header.
The API follows REST conventions with JSON request/response bodies. Version prefix /v1/ allows future breaking changes without disrupting existing clients. All endpoints return consistent error formats with machine-readable error codes and human-readable messages.
The translation service uses three storage systems, each chosen for a specific access pattern. Using a single database for everything would create a system that is mediocre at all three patterns instead of excellent at each.
The natural question is: why three databases? Because each data type has a fundamentally different access pattern. Translations need sub-millisecond key lookup at 50,000+ operations per second (Redis). User history needs relational queries with ACID transactions (PostgreSQL). Language model metadata needs infrequent reads with strong consistency (PostgreSQL). Forcing all three into a single store means either overpaying for Redis features you don't need for history, or accepting PostgreSQL latency for cache lookups that need to be sub-millisecond.
The architecture follows a standard request-response pattern with one critical addition: a caching layer that shields the expensive translation engine from the majority of traffic. Without this cache, the system would need 5x more GPU instances and cost 5x more to operate.
The design separates components by cost profile: cheap stateless CPU services handle request routing, authentication, and caching, while expensive GPU instances handle only the translation inference that cannot be avoided. This separation is the single most important architectural decision because it lets each component scale independently based on its own demand curve.
Understanding the request flow reveals why each component exists and how they interact. The translation request flow is the critical path — every millisecond of latency here is felt by the user.
The translation engine pipeline is the core of this system — it is the component that actually translates text. Everything else (caching, load balancing, circuit breakers) exists to protect this expensive component and make it efficient. Understanding the pipeline stages explains why translation is computationally expensive and where optimization opportunities exist.
Every architectural decision in this system involves a tradeoff between cost, quality, latency, and operational complexity. The choices below are the ones most likely to come up in an interview. For each tradeoff, the section presents both sides and explains which option this design chooses and why.
The common theme across all these tradeoffs: optimize for the common case while having a fallback for the uncommon case. The system does not try to handle every scenario perfectly — it handles the 80% case excellently and the 20% case acceptably.
In a distributed translation system, failures are not exceptional events — they are routine. The question is not whether the translation engine, cache, or network will fail, but how the system behaves when they do. Each failure scenario below has a specific mitigation that prevents cascading failures.
The design philosophy is defense in depth: every component has an explicit failure mode and a specific fallback. No single component failure should take down the entire service. The system degrades gracefully — from full-quality cached translations, to engine-backed fresh translations, to stale cached translations, to cache-only mode, to offline mode on the client. Each degradation level provides a worse but still useful experience.
When designing failure handling, the key question for each scenario is: what does the user see? A well-handled failure means the user gets a translation (possibly slightly stale or lower quality) with no visible error. A poorly-handled failure means the user sees a spinner followed by an error message. Every mitigation below optimizes for the user experience first and system health second.
These improvements extend the system beyond text-in, text-out translation. Each one builds on the existing architecture rather than requiring a redesign. The ordering below roughly follows implementation priority — speech translation and document translation are the highest-impact features, while multi-tenant isolation is infrastructure that enables enterprise growth.
Add a speech processing pipeline: voice input is transcribed to text (using a speech recognition model), translated via the existing NMT pipeline, and optionally synthesized back to speech (text-to-speech). The existing caching layer works for the translation step but not for speech recognition, which produces different text for the same spoken input depending on accent, background noise, and speaking speed. This requires streaming support — the client sends audio chunks, the server transcribes in real time, and translation begins before the speaker finishes.
Reading a solution is not the same as producing one under interview pressure. Design it on the whiteboard and get scored feedback.
0%
System requirements
Functional
Capacity estimation
Traffic
API design
Translation Endpoint
Database design
Redis — Translation Cache
High-level design
Request flows
Online Translation Flow
Detailed component design
Translation Engine Pipeline (GATE)
Tradeoffs
Third-Party vs Self-Hosted Translation
Failure scenarios
Future improvements
Speech-to-Text Translation
System requirements
Functional
Capacity estimation
Traffic
API design
Translation Endpoint
Database design
Redis — Translation Cache
High-level design
Request flows
Online Translation Flow
Detailed component design
Translation Engine Pipeline (GATE)
Tradeoffs
Third-Party vs Self-Hosted Translation
Failure scenarios
Future improvements
Speech-to-Text Translation