A reference MLOps setup: one command, with tracking, monitoring and CI
Most ML projects stop at the notebook. This one is a small system that runs with docker compose up --build and shows how the usual MLOps pieces fit together: serving, experiment tracking, monitoring and a CI pipeline.
What it is, and what it is not
It is a reference setup, not a production deployment. The vehicle inventory lives in memory, the sentiment model (TF-IDF with logistic regression) is retrained on every start, and the deploy step restarts the container, so it is not zero-downtime. Those are deliberate simplifications: complexity should be earned. What it does show is the wiring around the model, which is the part tutorials usually skip.
Two services, one platform
A vehicle inventory API (cars and motorcycles, stock changes, strict validation) and a sentiment API sit behind one FastAPI app, with one monitoring stack and one pipeline. Validation happens when the object is created, in __post_init__. One detail worth keeping: in Python bool is a subclass of int, so num_doors=True passes a plain integer check unless you test for bool first.
Experiment tracking
Every training run logs its parameters, metrics and model artifact to MLflow, so after a retrain you can compare two runs side by side instead of guessing. The vectorizer is fitted on the training split only, which keeps the logged metrics free of leakage.
Monitoring
Each prediction increments a labelled counter and records latency in a histogram. Prometheus scrapes them every 15 seconds and a Grafana dashboard shows totals, the positive/negative ratio and p95 latency. The ratio panel is the one to watch: a sudden shift from the usual split means the input data or the model changed.
PREDICTIONS = Counter('sentiment_predictions_total', 'Total predictions', ['label'])
PREDICTION_LATENCY = Histogram('sentiment_prediction_duration_seconds', 'Prediction latency')
CI/CD
Three stages: test, build, deploy. A stage runs only if the previous one passed. Images are tagged with the commit SHA, so every image traces to one commit and a rollback is a pull of the previous tag. The deploy job runs docker compose pull and up -d over SSH, which restarts the service. Rolling or blue-green deploys would be the next step.
Run it
git clone https://github.com/mtbagatur/vehicle-sentiment-mlops
cd vehicle-sentiment-mlops
docker compose up --build
API docs at localhost:8000/docs, MLflow on 5000, Grafana on 3000, Prometheus on 9090. The Grafana login in the compose file is a local demo credential: change it before exposing anything.