Chapter 13
Scalable Data Engineering, Cloud and MLOps
Post Graduate Program in AI and ML
Data Science
•
Post Graduate
Scalable Data Engineering, Cloud and MLOps
Introduction
Modern data science systems rarely fail because a model cannot be trained once. They fail because data arrives continuously, sources change, workloads exceed one machine’s capacity, deployments are unreliable, features differ between training and production, or model quality deteriorates after release. Scalable data engineering and MLOps address these operational problems by treating data, code, infrastructure, models, and monitoring as one engineered system.
Data engineering provides reliable batch and streaming pipelines. Cloud platforms provide elastic compute, managed storage, networking, identity, and observability. MLOps extends DevOps practices to machine-learning systems, whose behaviour depends not only on software but also on data distributions, labels, features, experiments, and model performance.
A production-quality system should be reproducible, observable, secure, cost-aware, and capable of controlled change. Scalability therefore means more than processing larger volumes. It also includes organizational scalability, operational resilience, governance, and the ability to support many models and teams.
Learning Objectives
After studying this chapter, learners should be able to:
Distinguish batch, micro-batch, and streaming architectures.
Design distributed data pipelines using suitable storage, compute, and orchestration components.
Explain cloud-native principles including elasticity, managed services, isolation, and cost control.
Package and expose models through APIs and containers.
Design feature stores, experiment-tracking systems, and CI/CD workflows for machine learning.
Select meaningful reliability, model-quality, and data-quality metrics.
Diagnose data drift, concept drift, training-serving skew, and operational failure.
Evaluate governance, security, ethical, and managerial implications of MLOps.
1. From Data Processing to Data Products
A data pipeline moves data from producers to consumers. Producers may include transactional databases, applications, sensors, files, logs, and external APIs. Consumers may be dashboards, analytical warehouses, feature stores, or prediction services.
A useful data-product perspective defines:
Inputs: source systems, schemas, contracts, and arrival patterns.
Transformations: validation, cleaning, joining, aggregation, and feature construction.
Outputs: tables, events, features, predictions, or reports.
Service-level objectives (SLOs): freshness, availability, latency, correctness, and cost.
Ownership: an accountable team, documentation, escalation path, and change policy.
Data quality is multidimensional. Common dimensions include completeness, validity, uniqueness, consistency, accuracy, and timeliness. A pipeline that produces records quickly but with invalid identifiers is not reliable.
Important terminology
Batch processing handles a bounded dataset, often on a schedule. Streaming processing handles an unbounded sequence of events. Micro-batch processing groups events into small time windows. Event time is when an event occurred; processing time is when the system handled it. This distinction matters when data arrives late or out of order.
A data contract specifies the expected schema, semantics, quality constraints, ownership, and compatibility policy between producers and consumers. Contracts reduce hidden dependencies and make changes explicit.
2. Batch and Streaming Architectures
Batch pipelines
A batch pipeline commonly extracts data, lands immutable raw data, validates it, transforms it, and publishes curated datasets. A layered design may contain:
Raw or bronze layer: source-faithful data, retained for replay.
Validated or silver layer: standardized types, deduplicated records, and quality checks.
Curated or gold layer: business-ready aggregates, dimensional tables, or features.
Batch processing is appropriate for periodic reporting, historical retraining, large joins, and workloads where minutes or hours of latency are acceptable. Its advantages include simpler reasoning, efficient large scans, and straightforward replay. Its limitations include delayed insight and expensive repeated processing when only a small amount of data changes.
Streaming pipelines
Streaming systems use producers, durable event logs or queues, consumers, state stores, and monitoring. Important design decisions concern partitioning, ordering, delivery guarantees, checkpointing, replay, and late data.
Sliding windows: overlapping intervals that advance periodically.
Session windows: intervals separated by periods of inactivity.
Exactly-once claims must be interpreted carefully. They generally require coordinated checkpointing, deterministic or idempotent processing, and compatible sinks. A system may provide exactly-once state updates while an external side effect remains at-least-once. Idempotent writes, deduplication keys, and transactional sinks are therefore important.
Throughput, latency, and capacity
If a system processes N records in T seconds, average throughput is:
R = N ÷ T
where R is throughput in records per second, N is the number of records, and T is elapsed time. This is an average measure and does not describe tail latency or bursts.
For a stable queueing system, Little’s Law relates average items in a system to arrival rate and time in the system:
L = λW
where L is the average number of items in the system, λ is the long-run average arrival rate, and W is the average time an item spends in the system. The relationship assumes a stable system over the measurement interval and consistent definitions of the system boundary. If events arrive at 200 events per second and the average end-to-end time is 3 seconds, the average number of in-flight events is 600.
Capacity planning must also consider burst rate, partition limits, serialization overhead, network bandwidth, state size, and recovery time. Increasing parallelism does not guarantee proportional speedup because coordination, skew, and I/O become bottlenecks.
Batch and streaming data architecture
Figure: Batch and streaming data architecture
Figure: A unified architecture in which batch and streaming paths publish governed data for analytical and machine-learning consumers.
3. Distributed Computing and Cloud Design
Distributed processing divides data and computation across workers. Partitioning enables parallelism, but poor partition keys create data skew: one worker receives disproportionately more records than others. Good partitioning seeks balanced distribution while preserving useful locality. Small files, excessive shuffles, repeated serialization, and unbounded state are common performance problems.
A practical distributed design uses immutable inputs, deterministic transformations, checkpointing, retries, and explicit handling of malformed records. Failed records should be isolated in a dead-letter or quarantine path rather than silently discarded.
Cloud platforms typically provide:
Capability
Engineering purpose
Object storage
Durable, scalable raw and curated data
Managed warehouse or lakehouse
SQL analytics and governed tables
Distributed compute
Batch transformations and model training
Message broker
Durable event transport and replay
Container platform
Portable services and jobs
Identity and key management
Authentication, authorization, and encryption
Monitoring and logging
Operational visibility and alerting
Cloud architecture should separate storage from compute where practical, use autoscaling cautiously, and apply least privilege. Elasticity can reduce idle capacity, but uncontrolled autoscaling can create unexpected costs. Cost allocation by team, workload, and environment supports accountability.
Reliability engineering
Availability is the proportion of agreed service time during which a service is usable:
Availability = (Agreed service time − Downtime) ÷ Agreed service time
The numerator and denominator must use the same time units and an agreed definition of downtime. Availability alone does not measure correctness, latency, or fairness. Recovery objectives are also essential: RPO specifies the maximum acceptable data loss measured in time, while RTO specifies the maximum acceptable restoration time.
4. Operationalizing Models
A model can be exposed through batch scoring, an online API, or an event-driven service. Online APIs require predictable latency, concurrency control, authentication, versioning, and graceful failure. Batch scoring is often cheaper and more reliable when predictions are needed periodically rather than interactively.
A model API should define input and output schemas, units, missing-value behaviour, error responses, model version, and correlation identifiers. It should avoid returning sensitive internal information and should validate inputs before inference.
Containers and orchestration
A container packages application code and dependencies into a reproducible runtime image. Good images are minimal, pinned to controlled base versions, scanned for vulnerabilities, and configured to run without unnecessary privileges. Configuration and secrets should be injected at runtime rather than embedded in images.
An orchestrator schedules containers, restarts failed instances, performs health checks, distributes traffic, and supports rolling or canary releases. Readiness indicates whether a service can receive traffic; liveness indicates whether it is functioning sufficiently to remain running. These probes should not be confused.
Deployment strategies include:
Blue-green: maintain two environments and switch traffic between them.
Canary: expose a small proportion of traffic to the new version first.
Shadow: send copied traffic to a new model without using its decisions.
Rollback: return to a previously validated version when defined criteria fail.
5. Feature Stores and Reproducible Features
A feature store manages reusable features for training and serving. Its major architectural concern is consistency between historical training data and online inference. An offline store supports large historical queries; an online store supports low-latency point lookups.
A feature definition should include name, semantic meaning, entity key, timestamp, data type, transformation code, freshness expectation, owner, and access policy. Point-in-time correctness is critical: a training example must use only information available at the prediction time. Otherwise, target leakage produces unrealistically strong evaluation results.
Training-serving skew occurs when the training transformation and production transformation differ. Shared transformation logic, feature validation, versioning, and lineage reduce this risk. Feature stores do not automatically solve poor feature definitions, stale data, privacy concerns, or causal ambiguity.
6. Experiment Tracking, CI/CD, and Workflow Orchestration
An experiment record should capture code version, data snapshot or query, feature definitions, hyperparameters, random seeds where relevant, evaluation results, environment, and model artifact. A model registry can organize candidate, validated, staging, and production versions with approval history.
CI validates code through tests, static analysis, dependency checks, schema checks, and reproducible builds. CD promotes artifacts through environments using automated gates. Machine-learning delivery adds tests for data distributions, feature availability, prediction ranges, fairness indicators, and model quality.
Pipeline orchestration coordinates dependencies, retries, schedules, backfills, parameterization, and lineage. A robust workflow is idempotent: rerunning the same logical interval does not create duplicate or contradictory outputs. Backfills should be isolated from current production writes and should explicitly define how historical logic is versioned.
A useful promotion policy may require:
all software and data-quality tests to pass;
evaluation on a fixed, representative holdout set;
no prohibited fairness or safety regression;
reproducible artifact and dependency metadata;
human approval for high-impact applications; and
a rollback plan with an observable release identifier.
missingness, ranges, category changes, duplicates, distribution shifts
Model
latency, calibration, error, business utility, subgroup performance
The error rate for n labelled observations is:
Error rate = (Number of incorrect predictions) ÷ n
This metric is meaningful only when labels are correctly defined and the evaluation sample is relevant. Accuracy can be misleading under class imbalance; precision, recall, calibration, cost-weighted loss, and subgroup metrics may be more appropriate.
Data drift is a change in input distributions. Concept drift is a change in the relationship between inputs and the target. Prediction drift is a change in model outputs. Drift is a signal for investigation, not automatic proof that a model is unusable.
For a binary classifier, precision and recall are:
Precision = TP ÷ (TP + FP)
Recall = TP ÷ (TP + FN)
TP, FP, and FN denote true positives, false positives, and false negatives. The formulas assume a defined positive class and a classification threshold. In credit, medicine, or safety applications, the cost of FP and FN may differ substantially.
A drift-management process should define baselines, windows, thresholds, alert severity, ownership, and actions. Actions may include investigation, recalibration, feature repair, threshold adjustment, retraining, rollback, or retirement. Automated retraining without data validation can amplify a temporary anomaly or poisoned data.
8. Case Study: Illustrative Real-Time Fraud Detection Platform
Background
Consider a fictional payment company processing card transactions. It initially runs a nightly batch model, but fraud losses occur before the next scoring cycle. The company wants decisions within 300 milliseconds while retaining historical data for investigation and retraining.
Problem analysis
Transactions arrive as events. Useful features include recent transaction count, geographic distance, merchant history, and account age. Some labels become available only after disputes, weeks after the original event. This creates delayed feedback and makes immediate accuracy measurement impossible.
Approach
The company stores immutable transaction events in object storage and a durable event log. A streaming processor validates schemas, enriches events with point-in-time-safe features, and writes online features to a low-latency store. An API retrieves features and returns a model score. A separate batch path creates historical training datasets and reconciles late labels.
The deployment uses a containerized service behind an authenticated gateway. A canary release receives 5% of traffic, with rollback based on latency, error rate, service availability, and later fraud outcomes. The model registry records the training data interval, code revision, feature definitions, and approval decision.
Monitoring covers event backlog, feature freshness, missing merchant identifiers, API p95 latency, score distribution, approval rate, confirmed fraud rate, and subgroup differences. If the event stream is delayed, the service uses a documented fallback policy rather than silently substituting stale features.
Outcome
The architecture reduces decision latency and supports replay, but it does not eliminate uncertainty. Labels remain delayed, fraud strategies evolve, and false positives impose customer costs. Governance therefore requires periodic review, human escalation for borderline cases, access controls, retention limits, and an appeal process.
Learning points
The case demonstrates that an MLOps solution is a socio-technical system. Low latency is only one objective. Correct temporal joins, resilient data paths, monitored business outcomes, transparent release controls, and responsible use of personal data are equally important.
9. Governance, Security, and Responsible Operation
Production data systems may process personal, financial, health, or behavioural information. Governance should address lawful purpose, consent where required, data minimization, retention, deletion, access logging, encryption, segregation of duties, and cross-border transfer rules. Applicable regulations vary by jurisdiction and sector; technical controls must be mapped to organizational and legal requirements rather than treated as universal substitutes for legal advice.
Model governance should document intended use, excluded use, limitations, training population, evaluation design, known failure modes, human oversight, and change history. Privacy risks include excessive collection, re-identification, inference of sensitive attributes, and leakage through logs or feature stores. Security threats include credential theft, supply-chain compromise, data poisoning, model extraction, prompt or input manipulation, and unauthorized model access.
Responsible practice requires testing performance across relevant subgroups, investigating disparate error patterns, communicating uncertainty, and ensuring that operational incentives do not encourage unsafe optimization. Reproducibility and auditability are not merely research conveniences; they support incident response and accountability.
10. Contemporary Developments and Best Practices
Current engineering practice increasingly combines lakehouse storage, event-driven architectures, declarative infrastructure, policy-as-code, managed model endpoints, and specialized observability platforms. Generative AI systems add retrieval pipelines, evaluation of factuality and harmful outputs, prompt and document versioning, and protection against indirect prompt injection. These developments do not replace fundamental disciplines such as data contracts, access control, testing, and monitoring.
Recommended practices are:
Start with explicit SLOs and business risks, not fashionable tools.
Preserve raw data and metadata sufficiently for replay and audit.
Make transformations deterministic, versioned, and testable.
Design for late, duplicated, malformed, and missing events.
Separate training, staging, and production access.
Use point-in-time-correct features and prevent leakage.
Automate testing and artifact promotion, but retain appropriate human gates.
Monitor tail latency, freshness, quality, cost, model outcomes, and subgroups.
Define rollback, incident response, and retirement procedures before release.
Review whether the model remains useful, fair, secure, and economically justified.
Chapter Summary
Scalable data engineering combines reliable storage, distributed computation, data contracts, quality controls, orchestration, and observability. Batch systems are effective for bounded, periodic workloads, while streaming systems support low-latency decisions but require careful treatment of event time, state, ordering, replay, and delivery guarantees. Cloud platforms provide elasticity and managed capabilities, yet introduce cost, security, and dependency considerations.
MLOps operationalizes models through APIs, containers, orchestration, feature stores, experiment tracking, registries, CI/CD, and monitoring. Production quality depends on reproducibility, point-in-time correctness, idempotence, controlled deployment, and rollback. Monitoring must cover infrastructure, pipelines, data, models, business outcomes, and relevant subgroups. Drift is a diagnostic signal requiring investigation rather than an automatic retraining command. Governance, privacy, security, fairness, and human accountability are integral to reliable machine-learning products.
Key Terms
Data contract: Agreement defining schema, semantics, quality, ownership, and compatibility.
Batch processing: Processing a bounded dataset, usually on a schedule.
Streaming processing: Continuous processing of an unbounded event sequence.
Event time: Time at which an event occurred.
Processing time: Time at which a system processes an event.
Partitioning: Dividing data into units processed in parallel.
Data skew: Uneven distribution of work across parallel workers.
Idempotence: Property that repeating an operation produces the same intended result.
Checkpoint: Persisted processing state used for recovery.
SLO: Quantified target for a service characteristic such as latency or availability.
RPO: Maximum acceptable time-based amount of data loss.
RTO: Maximum acceptable time to restore service.
Feature store: System managing reusable features for training and serving.
Training-serving skew: Difference between feature computation in training and production.
Model registry: Repository of versioned models and their approval metadata.
Canary deployment: Gradual release to a small traffic proportion.
Data drift: Change in input-data distributions.
Concept drift: Change in the relationship between inputs and outcomes.
Point-in-time correctness: Use of only information available at the prediction time.
MLOps: Practices for developing, deploying, operating, and governing machine-learning systems.
Review Questions
Short Answer Questions
What is the difference between event time and processing time?
Define a data contract and explain its purpose.
What is training-serving skew?
Distinguish RPO from RTO.
Why is model drift not, by itself, proof that retraining is required?
Long Answer Questions
Compare batch, micro-batch, and streaming architectures, including their reliability and operational trade-offs.
Explain how containers, orchestration, model registries, and CI/CD work together in a production ML system.
Discuss the design of a feature store and the importance of point-in-time correctness.
Develop a monitoring framework covering infrastructure, pipelines, data, models, and business outcomes.
Evaluate the governance, privacy, security, and fairness requirements of a high-impact predictive application.
Analytical / Application Questions
A pipeline receives 200 events per second and has an average end-to-end delay of 3 seconds. Use Little’s Law to estimate the average number of in-flight events. State the assumptions.
Design a batch and streaming architecture for an online retailer that needs hourly demand forecasts and real-time inventory alerts. Justify storage, processing, feature, and monitoring choices.
A new model reduces overall error but increases false negatives for a protected subgroup. Propose an investigation, release decision, and remediation plan.
Multiple Choice Questions with Answers
Question 1
Which workload is most naturally suited to batch processing?
A. A bounded historical retraining dataset processed nightly
B. A fraud decision requiring a response within 100 milliseconds
C. A sensor alert requiring continuous event handling
D. A live API request requiring an immediate prediction
Correct Answer: A. A bounded historical retraining dataset processed nightly
Question 2
In a stable system, an arrival rate of 200 events per second and an average time in the system of 3 seconds imply, by Little’s Law, an average of:
A. 67 events
B. 200 events
C. 600 events
D. 6,000 events
Correct Answer: C. 600 events
Question 3
Which practice best prevents training-serving skew?
A. Using different undocumented transformations in each environment
B. Sharing versioned transformation logic between training and serving
C. Removing timestamps from all features
D. Retraining whenever API latency increases
Correct Answer: B. Sharing versioned transformation logic between training and serving
Question 4
What is the primary purpose of a model registry?
A. To replace all data storage
B. To provide network routing for containers
C. To store only raw event streams
D. To manage versioned model artifacts and approval metadata
Correct Answer: D. To manage versioned model artifacts and approval metadata
Question 5
Which deployment exposes a new model to a small proportion of production traffic first?
A. Canary deployment
B. Blue-green deletion
C. Full cutover
D. Offline archival
Correct Answer: A. Canary deployment
Question 6
If TP = 90 and FP = 10, what is precision?
A. 0.10
B. 0.50
C. 0.90
D. 0.99
Correct Answer: C. 0.90
Question 7
Which statement correctly describes concept drift?
A. The storage bucket has reached its capacity
B. The relationship between inputs and the target has changed
C. The API has a new URL
D. The model image has been compressed
Correct Answer: B. The relationship between inputs and the target has changed
Question 8
Which feature-store property ensures that future information is not used in a historical training example?
A. Point-in-time correctness
B. Autoscaling
C. Container isolation
D. Canary routing
Correct Answer: A. Point-in-time correctness
Question 9
What does RTO specify?
A. The acceptable amount of model bias
B. The maximum time to restore service
C. The number of training features
D. The rate of incoming events
Correct Answer: B. The maximum time to restore service
Question 10
Which action is most appropriate when a drift alert occurs?
A. Automatically retrain on unvalidated data in every case
B. Ignore the alert because drift is always harmless
C. Investigate data quality, labels, business impact, and model performance
D. Delete the historical training data
Correct Answer: C. Investigate data quality, labels, business impact, and model performance