Welcome to the next lesson in our journey through data management for ML systems. In our previous session, we established a framework for versioning data, schemas, and models to ensure that every result from our system is reproducible and auditable. We focused on tracking the static artifacts of our ML pipeline. Now, we shift our attention to the dynamic behavior of the system when it's live in production.
This lesson addresses the learning outcome: Design a logging and event collection architecture for monitoring and debugging ML systems. We will explore how to build a robust pipeline to capture, process, and analyze the vast streams of data generated by a production ML service. This is the foundation for everything from real-time debugging during an outage to proactively detecting model performance degradation. For ML system design interviews, demonstrating a solid understanding of logging and monitoring architecture is non-negotiable, as it signals operational maturity and an understanding of what it takes to run reliable systems at scale.
Why and What to Log in an ML System
In any distributed system, especially one composed of microservices, logs are the primary tool for observability. Without a centralized way to collect and search logs, debugging becomes a nightmare of manually accessing dozens or hundreds of servers.
This short video segment provides an excellent overview of the problem and why a centralized, distributed logging system is a fundamental requirement for any modern software architecture.
Distributed Logging System Design with Ex-Amazon SDE
This clip sets the stage by contrasting the old, painful way of handling logs with the modern, centralized approach necessary for microservices.
Please watch from the beginning until the introduction. The speaker effectively describes the core problems of slow debugging and lack of visibility that a distributed logging system aims to solve.
While we need to log standard software metrics, ML systems introduce unique monitoring challenges. A service can be operating perfectly from a software perspective (low latency, no errors) while producing incorrect or harmful predictions. Therefore, our logging strategy must be two-pronged.
The following guide from Evidently AI provides a clear breakdown of the different categories of metrics we need to capture.
Model monitoring for ML in production: a comprehensive ...
This reading is crucial as it differentiates general software monitoring from the specific needs of ML systems. It answers the question, "What should we be logging?"
Please read the section on monitoring metrics. As you read, categorize the metrics into these key groups: Software/Operational Health: Standard metrics like latency, error rate, CPU/memory. Data Quality: Metrics tracking the integrity of input data (e.g., missing values, schema violations). Model Quality: Direct performance measures like accuracy, precision, recall (when ground truth is available). Data and Prediction Drift: Proxy metrics that signal when the model is operating on unfamiliar data, often a precursor to performance degradation.
To summarize, a complete ML logging system must capture events that allow us to monitor all four of these areas. Simply logging HTTP 200 success codes is not enough; we must also log the feature inputs and model outputs to detect issues like data drift and concept drift, which are central to MLOps.
Architecting a General-Purpose Logging Pipeline
Now that we know what to log, let's design the system to handle it. A distributed logging pipeline typically follows a standard pattern, often referred to as the journey of a single log event.
The high-level stages are:
- Collection: An agent on each server gathers logs locally.
- Ingestion & Buffering: A centralized service receives logs from all agents and places them in a durable buffer. This decouples the log producers from the processors.
- Processing: Logs are parsed, structured, enriched with metadata, and potentially filtered or aggregated.
- Storage: Processed logs are sent to one or more specialized storage systems depending on the use case (e.g., search, time-series analysis, long-term archival).
- Query & Visualization: End-users interact with the logs through dashboards and query interfaces.
The following diagram illustrates a popular implementation of this pattern, commonly known as the ELK Stack (Elasticsearch, Logstash, Kibana) augmented with Kafka.

This architecture is robust and widely used. The next video provides a detailed, step-by-step walkthrough of building such a system, explaining the role of each component. This is an excellent, practical design that you can adapt for an interview setting.
Distributed Logging System Design with Ex-Amazon SDE
This video walks through a complete end-to-end design, explaining the specific technologies used at each stage. It's a fantastic blueprint for a system design interview answer.
Please watch the following segments, which cover the entire pipeline: High-Level Design: This covers collection with log agents (like Filebeat), the importance of correlation IDs for tracing, and buffering with Kafka. Stream Processing: This explains the role of Apache Flink (a more powerful alternative to Logstash) in parsing, enriching, filtering, and aggregating logs. Storage Backends: This details the multi-tiered storage strategy: Elasticsearch for search, TimescaleDB for metrics, and S3 for archiving. Querying and Dashboards: This shows how developers use tools like Kibana, Grafana, and Athena to interact with the stored data.
The design presented in the video is powerful because it's not a "one-size-fits-all" approach to storage. It correctly identifies that different use cases require different storage solutions:
- Debugging: Requires fast, full-text search across raw, enriched logs. Elasticsearch is ideal for this.
- Monitoring & Alerting: Relies on aggregated, numerical time-series data (e.g., error rate per minute, P95 latency). A time-series database like TimescaleDB or Prometheus is optimized for this.
- Compliance & Offline Analysis: Requires long-term, low-cost storage of all logs. An object store like Amazon S3, with logs stored in a columnar format like Parquet, is perfect for this.
This multi-backend strategy is a key hallmark of a mature system design.
Specializing the Architecture for ML Monitoring
We now have a robust architecture for general-purpose logging. The final step is to explicitly show how it supports the ML-specific monitoring requirements we identified earlier.
The core idea is to treat the logs from our ML model—specifically the captured predictions and feature inputs—as the primary data source for a specialized monitoring service.
This diagram conceptualizes the flow for ML monitoring:

Let's map this concept onto the architecture we just designed:
- The "ML service" is one of the microservices in our system. It logs predictions, inputs, and other events.
- The logs are collected and sent to Kafka, which acts as a temporary "Prediction store" or event bus.
- An "ML Monitoring service" can be implemented as a Flink job that consumes from Kafka. This job calculates data quality metrics, drift statistics, and other proxy metrics in real-time.
- Alternatively, "Monitoring jobs" can be batch processes (e.g., a daily Spark job or a SageMaker Processing Job) that read the archived logs from S3 to compute metrics. This is common for calculating model accuracy when ground truth labels arrive with a delay.
- The computed metrics are written to a "Metric store", which is our time-series database (e.g., TimescaleDB).
- The "Monitoring dashboard" is our Grafana instance, which visualizes the metrics from the metric store.
Let's look at a concrete, cloud-native implementation of this pattern using AWS. The following video on Amazon SageMaker Model Monitor demonstrates this exact flow.
AWS re:Invent 2020: Detect machine learning (ML) model drift in production
This video from AWS provides a practical walkthrough of setting up an end-to-end ML monitoring pipeline on a major cloud platform. It brings together all the concepts we've discussed.
Watch the following segments to understand the key steps: End-to-end architecture: This section outlines the process: deploying a model with data capture enabled, running a "baselining" job on the training data to create reference statistics, and then creating a monitoring job to compare live traffic against the baseline. Detecting accuracy drift: This explains how to extend the system to monitor true model quality by merging captured predictions with ground truth data. Taking action: This is a critical part. It shows how violations detected by the monitoring jobs emit metrics to CloudWatch, which can trigger alarms and automated actions, such as kicking off a model retraining pipeline.
The SageMaker example perfectly illustrates how a general logging and event collection architecture serves as the backbone for a sophisticated MLOps workflow. The Data Capture feature is the collection mechanism, S3 is the storage layer, the Monitoring Jobs are the processing layer, and CloudWatch provides the metric storage, visualization, and alerting capabilities.
Conclusion
In this lesson, we designed a comprehensive architecture for logging and event collection, tailoring it specifically for the demands of production machine learning systems. You are now equipped to articulate a design that handles the scale and complexity of real-world monitoring.
Key Takeaways:
- ML monitoring requires more than just operational metrics. You must log data to track data quality, model quality, and data/concept drift.
- A robust logging architecture follows a five-stage pattern: Collect -> Buffer -> Process -> Store -> Visualize.
- Key technologies in a modern pipeline include collection agents (Filebeat), a message queue for buffering (Kafka), a stream processor for enrichment and aggregation (Flink), and a multi-tiered storage system (Elasticsearch, TimescaleDB, S3).
- The general-purpose logging infrastructure is the foundation for specialized ML monitoring services that consume prediction logs, compute drift and quality metrics, and trigger automated workflows like alerts and retraining.
This lesson concludes our module on Data Management and Governance. We have covered how to ingest, validate, version, and now monitor the data and artifacts that power our ML systems. In the next module, we will dive deep into a critical component that sits at the heart of many of these data flows: the Feature Store. We will explore how to design a centralized system for managing, serving, and versioning features for both training and real-time inference.