Model Deployment & Prediction Service
ML Engineer path · lesson 73 of 80Deploying is easy if you ignore all the hard parts. Four myths against the Uber, Booking.com and Algorithmia numbers, batch against online prediction, a compression slider that reproduces the Roblox 7x result, and why the browser is an edge device.
predict in a Flask or FastAPI POST endpoint, containerising the dependencies and pushing to a cloud gives a functional deployment in an hour. The hard parts are millisecond latency for millions of users, 99% uptime, alerting the right person immediately, diagnosing what went wrong, and seamlessly shipping the fix. And separating the team that builds from the team that deploys causes high cross-team communication overhead, slow updates and hard debugging.Key insight
Josh Wills, formerly of Google and Slack: “We are always trying to bring new models into production just as fast as humanly possible.” That is the posture myth 3 is arguing for — update frequency as a capability you build, rather than a schedule you negotiate.
Batch or online prediction?
Sort each trait into the prediction pattern it describes.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Batch
Drop items hereOnline
Drop items hereTest your knowledge
Wrapping a predict function in a Flask endpoint, containerizing it and pushing to a cloud provider takes roughly:
The short version
A restaurant choosing between a buffet and a kitchen. The buffet cooks everything in advance — enormous throughput, nothing waits, and it cannot serve a dish nobody anticipated. The kitchen cooks on demand — anything on the menu, but every diner waits for the stove.
In more depth
Model Deployment & Prediction Service
"Deploying is easy if you ignore all the hard parts." Wrapping
predictin a Flask or FastAPI endpoint, containerizing and pushing to AWS gives a functional deployment in an hour. The hard parts are millisecond latency for millions of users, 99% uptime, alerting the right person, diagnosing the cause, and shipping the fix seamlessly.
Exporting a model — also called serialization — has two parts, the model definition (how many hidden layers, how many units) and the parameter values. tf.keras.Model.save() produces SavedModel; torch.onnx.export() produces ONNX.
Four myths
Batch vs online
Three modes: batch prediction with batch features · online prediction with batch features · online prediction with batch and streaming features, also called streaming prediction.
| Batch (asynchronous) | Online (on-demand) | |
|---|---|---|
| Frequency | periodical, e.g. every four hours | as soon as requests come |
| Useful for | accumulated data, no immediate need — recommender systems | fraud detection |
| Optimized for | high throughput | low latency |
Streaming features are not online features. Online features are any feature used for online prediction, including batch features held in memory — item embeddings are online but not streaming.
Grubhub had 31 million users and 622,000 daily orders in 2020 — at 2% daily logins, batch prediction wastes 98% of the compute.
Compression
Low-rank factorization — SqueezeNets: AlexNet accuracy, 50x fewer parameters. MobileNets: K² + C instead of K²C, an 8-9x reduction at K=3.
Knowledge distillation — DistilBERT: 40% smaller, 97% of understanding retained, 60% faster. Works across architectures; needs a teacher.
Pruning — usually set the least useful parameters to 0, making the network sparse. Over 90% of nonzero parameters can go without compromising accuracy.
Quantization — "the most general and commonly used". 100M parameters at 32 bits = 400 MB. XNOR-Net's authors spun off Xnor.ai, acquired by Apple in early 2020 for a reported $200M.
Roblox, scaling BERT to 1+ billion daily requests on CPUs at 25,000 inferences per second under 20 ms: BERT → DistilBERT → dynamic shape input → quantize. The biggest boost was quantization: 7x lower latency, 8x higher throughput.
Cloud vs edge
Compiling: TPUs shipped February 2018; PyTorch support arrived September 2020. Intermediate representation is the middleman, and generating it is called lowering — "it's not translating because there's no one-to-one mapping."
A Stanford DAWN study found typical NumPy/pandas/TensorFlow workloads run 23 times slower in one thread than hand-optimized code. autoTVM needs about 70 trials to beat cuDNN for ResNet-50 on an NVIDIA TITAN X.
WebAssembly is supported by 93% of devices worldwide (September 2021) but runs 45% (Firefox) to 55% (Chrome) slower than native.
"Deploying ML models is an engineering challenge, not an ML challenge."
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required