KatInterview

Containerizing and Shipping a Python Model Server

System DesignModel answer
EasyModel answerSystem Designdockerci-cdmlops

Last updated

Explain how containers work, tighten a naive Dockerfile for an ML inference API, and outline a CI/CD pipeline that safely ships code and model changes.

You own a Python service that loads a trained model and returns predictions over HTTP. It is packaged as a Docker image and released through an automated pipeline. Assume typical ML dependencies: a deep learning framework, text or feature-processing libraries, and some packages with native extensions.

No targets for image size, build time, startup time, or latency are given. Decide what to clarify first, and justify every change by the bottleneck it removes.

Part 1 - Container fundamentals. Explain the difference between an image and a container. Describe how layers and the build cache work, and what isolates a container from its host. Compare containers with virtual machines and state the practical consequences.

Part 2 - Improve the Dockerfile. Starting from the file below, describe how you would make the image smaller, quicker to build, quicker to start, and efficient at runtime. Cover security and reproducibility as well.

FROM python:3.11
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y build-essential git
RUN pip install -r requirements.txt
CMD ["python", "serve.py"]

Part 3 - CI/CD. Define continuous integration, continuous delivery, and continuous deployment, and say how delivery differs from deployment. Then describe a pipeline that carries a change (code or a new model) from commit to a running production container, including ML-specific checks, how the model version is tied to the deployment, and how you roll out and roll back safely.

Questions you may ask before answering: which cost hurts most (image pull time, CI time, cold start, or throughput); CPU or GPU hosts; whether weights are baked into the image or fetched at startup; and what runs the containers and how often you redeploy.

Hints

Hint 1

Start from the cost that hurts most. Image size, CI time, cold start, and throughput each lead to different fixes, so name the bottleneck before each change.

Hint 2

For the Dockerfile, think about which instructions change most often and put them last. Also separate what is needed to build from what is needed to run.

Hint 3

For CI/CD, treat the image as an immutable artifact identified by a tag or digest. Promote the same artifact through environments instead of rebuilding it, and always keep a known-good version to roll back to.