Big Data and Cloud Analytics

Chapter 10
Machine Learning and Generative AI at Scale

Post Graduate Diploma in Data Science
Big Data and Cloud Analytics   •   Post Graduate

10. Machine Learning and Generative AI at Scale

Introduction and Context

Machine learning has moved from a specialist modelling activity to an operational capability embedded in search, fraud detection, recommendation, logistics, healthcare, finance, and public administration. The defining challenge in big data environments is no longer simply choosing an algorithm. It is constructing a reliable system that can transform large and rapidly changing data collections into features, train models across distributed infrastructure, serve predictions with acceptable latency, and monitor whether the model remains useful after deployment.

Generative artificial intelligence extends this challenge. Instead of only predicting a class, score, or numerical value, generative models produce text, code, images, audio, or structured outputs. Their practical use depends on foundation models, prompt design, retrieval-augmented generation (RAG), vector databases, evaluation, security, and governance. Scale introduces both opportunity and risk: larger datasets may improve coverage, but they also increase computational cost, privacy exposure, data-quality problems, and the difficulty of detecting failure.

This chapter examines machine learning and generative AI as cloud-scale systems. It connects feature engineering, distributed training, inference architecture, cloud AI services, foundation models, embeddings, vector search, RAG, and responsible AI. The central argument is that successful AI is socio-technical: algorithms, data pipelines, infrastructure, people, controls, and business objectives must be designed together.

Learning Objectives

After studying this chapter, students should be able to:

1. Explain why machine learning at scale requires distributed data and computing architectures.

2. Design scalable feature-engineering and feature-management workflows.

3. Compare distributed training, batch inference, online inference, and streaming inference.

4. Assess managed cloud AI services against self-managed and open-source alternatives.

5. Explain foundation models, embeddings, vector databases, and retrieval-augmented generation.

6. Select appropriate evaluation measures for predictive and generative systems.

7. Identify operational, ethical, privacy, security, and governance risks.

8. Propose a responsible architecture for deploying AI in an organizational setting.

From a Model to an AI System

A machine-learning model is a parameterized function learned from data. In supervised learning, a training set contains observations, features, and a target. The model minimizes a loss function, such as mean squared error for regression or cross-entropy for classification. In unsupervised and self-supervised learning, the learning signal is derived from the data itself; this is central to modern foundation models.

In production, however, the model is only one component. A useful AI system includes data ingestion, validation, feature computation, training, model registration, deployment, prediction serving, monitoring, security, and governance. This broader perspective is often called the machine-learning lifecycle or MLOps. A model that achieves high offline accuracy but receives stale features, cannot be reproduced, or fails under production load is not a successful system.

Scale has several dimensions. Data volume may require distributed storage and parallel processing. Data velocity may require streaming features and near-real-time inference. Model size may require GPUs, specialized accelerators, model parallelism, or quantization. User demand may require autoscaling and low-latency serving. Finally, organizational scale requires reproducible pipelines, access controls, audit trails, and clear ownership.

Important terminology

A feature is an input variable supplied to a model. Feature engineering transforms raw data into representations that expose useful signals. A label is the target value used in supervised learning. Training is the optimization of model parameters; validation supports model selection and hyperparameter tuning; testing estimates performance on held-out data. Inference is the process of generating predictions from a trained model.

A pipeline is an ordered, automated sequence of data and model operations. A model registry stores versioned models and metadata. Model drift describes a change that reduces performance after deployment. Data drift concerns changes in input distributions, while concept drift concerns changes in the relationship between inputs and the target. An endpoint is a network-accessible prediction service. A feature store manages reusable, governed features for training and serving.

Scalable Feature Engineering

Feature engineering at scale begins with a data contract. The contract specifies schema, units, acceptable ranges, ownership, update frequency, missing-value policy, and privacy classification. Without such agreements, teams may silently train on incompatible or incomplete data. Automated schema validation should occur before transformation, and data-quality results should be recorded as metadata rather than treated as informal observations.

Distributed processing frameworks divide a large dataset into partitions that can be processed in parallel. Columnar formats such as Parquet reduce scanning costs when only selected columns are required. Partitioning by date, region, or another high-value filter can reduce computation, although excessive or poorly chosen partitions create small-file and metadata problems. Transformations should be designed to minimize data movement. Joins, especially large shuffles, are often more expensive than local map operations; appropriate partitioning, broadcast joins for genuinely small tables, and pre-aggregation can improve performance.

Feature transformations must also be statistically valid. A common error is target leakage: using information that would not have been available at prediction time. For example, using a customer’s final repayment status to predict whether a loan will default produces an apparently strong but operationally useless model. Time-aware feature construction uses event timestamps and cutoff times to ensure that only historically available data is used.

A feature store commonly separates an offline store from an online store. The offline store supports historical training datasets, reproducibility, and backtesting. The online store supports low-latency retrieval during inference. The critical design requirement is training-serving consistency: a feature should be computed with equivalent definitions in both environments. Point-in-time joins are especially important because they reconstruct the feature values that were available at a historical moment.

Feature engineering may use aggregations, categorical encoding, normalization, text representations, embeddings, graph statistics, or time-window calculations. At scale, these operations should be parameterized, versioned, tested, and observable. Recomputing all historical features for every experiment is inefficient; incremental processing and materialized intermediate results can reduce cost. Nevertheless, caching must not compromise correctness when source data changes.

Distributed Training and Model Development

Distributed training uses multiple workers to reduce training time or enable models that do not fit on one machine. In data parallelism, each worker holds a copy of the model and processes a different mini-batch. Gradients are aggregated, often through an all-reduce operation, and model parameters are synchronized. Data parallelism is effective when the model fits on each worker and communication costs are manageable.

In model parallelism, different parts of a model are placed on different devices. Pipeline parallelism divides layers into stages, while tensor parallelism divides mathematical operations. These approaches are valuable for very large neural networks but introduce scheduling and communication complexity. Hybrid strategies combine data and model parallelism.

Distributed training is not automatically efficient. If workers frequently wait for the slowest worker, the system experiences stragglers. Network bandwidth, synchronization frequency, data loading, checkpointing, and GPU utilization all influence performance. Increasing batch size may improve hardware utilization but can affect optimization and generalization. A scalable experiment therefore records not only accuracy but also elapsed time, throughput, resource utilization, energy or cost, and reproducibility information.

Hyperparameter tuning can itself be distributed. Grid search is simple but often wasteful. Random search explores continuous spaces more effectively, while Bayesian optimization uses previous results to select promising configurations. Early stopping and successive-halving methods terminate weak trials before they consume substantial resources. Tuning must be performed against a validation strategy that reflects deployment; random splits are inappropriate when observations are time-dependent or grouped by customer, patient, device, or location.

Reproducibility requires versioned code, data snapshots or immutable references, feature definitions, model parameters, random seeds where meaningful, environment specifications, and experiment metadata. Perfect bitwise reproducibility may be difficult on heterogeneous accelerators, but procedural reproducibility should remain a design objective.

Inference Architecture: From Batch Scoring to Real Time

Batch inference generates predictions for a large population on a schedule. It is suitable for monthly risk reports, recommendation tables refreshed overnight, or inventory forecasts. It is usually economical because resources can be allocated in large jobs and latency is not a user-facing constraint.

Online inference responds to individual requests through an endpoint. It requires predictable latency, version management, authentication, autoscaling, and protection against malformed or adversarial input. A model may be deployed as a synchronous service, behind a queue, or as part of a microservice. Streaming inference processes events continuously and is appropriate for fraud detection, sensor monitoring, and personalization, but it requires careful handling of event time, late data, duplicate events, and state.

A useful design distinguishes model latency from total system latency. Feature retrieval, network calls, serialization, safety checks, and post-processing may dominate the model’s computation. Techniques such as batching, caching, quantization, distillation, compiled runtimes, and specialized hardware can reduce cost or latency. A fallback model or rule-based policy may be necessary when the primary service is unavailable.

Deployment strategies include blue-green deployment, in which traffic moves between two environments; canary deployment, in which a small fraction of traffic is routed to a new version; and shadow deployment, in which a candidate model receives copies of requests without affecting decisions. These strategies reduce the risk of releasing a poorly performing model. Monitoring should cover technical indicators such as latency and error rate, data indicators such as missingness and drift, and outcome indicators such as precision, loss, revenue, harm, or user complaints.

Cloud AI Services and Architectural Choices

Cloud providers commonly offer managed services for data preparation, notebooks, distributed training, model registries, feature stores, endpoints, document processing, speech, vision, and foundation-model access. Their principal advantages are elastic capacity, managed security integrations, operational tooling, and rapid experimentation. They can be particularly attractive when an organization lacks specialist infrastructure staff or needs temporary access to expensive accelerators.

Managed services also create trade-offs. Pricing may be complex, workloads can become dependent on proprietary interfaces, data movement can create cost and compliance concerns, and the organization may have limited visibility into model internals. Service-level guarantees, geographic processing locations, retention policies, subcontractors, and version changes require review. A cloud decision should therefore consider total cost of ownership, portability, latency, governance, skills, and strategic dependence—not only the advertised model quality.

Self-managed open-source systems offer control, customization, and portability, but the organization assumes responsibility for patching, scaling, observability, security, accelerator compatibility, and incident response. A hybrid architecture may keep sensitive data and certain models within controlled infrastructure while using cloud services for elastic training or general-purpose capabilities. Architecture decisions should follow data classification and risk appetite rather than fashion.

Foundation Models, Embeddings, and Vector Databases

A foundation model is a large model trained on broad data and adapted to many downstream tasks. Language foundation models learn statistical relationships among tokens through objectives such as next-token prediction. They can then be prompted, fine-tuned, or connected to external tools. Their broad capability does not imply factual reliability, domain completeness, or safe behavior.

An embedding maps an object—such as a document, sentence, image, product, or user—to a numerical vector. Semantically similar objects are expected to occupy nearby regions under a chosen similarity measure, commonly cosine similarity or a distance metric. Embeddings support semantic search, clustering, duplicate detection, recommendation, and retrieval for generative systems.

A vector database stores embeddings and associated metadata and provides approximate nearest-neighbour search. Approximate methods trade a small amount of recall for speed and memory efficiency. Metadata filtering is essential: similarity alone should not retrieve a document from the wrong department, jurisdiction, date range, or access group. Index choice, embedding model, chunk size, overlap, update frequency, and filtering strategy all influence retrieval quality.

Vector search is not a replacement for conventional databases. Relational databases remain appropriate for transactions, exact conditions, joins, and integrity constraints. Search systems may combine lexical retrieval, structured filters, and vector retrieval. Hybrid retrieval is often stronger than relying on one method because exact names and codes may be poorly represented by semantic similarity.

Retrieval-Augmented Generation

Retrieval-augmented generation combines a generative model with an information-retrieval pipeline. During ingestion, authoritative documents are collected, cleaned, divided into chunks, embedded, and indexed. At query time, the user question may be rewritten, relevant passages are retrieved, filters are applied, and the passages are inserted into a prompt. The model generates an answer grounded, ideally, in the retrieved evidence.

RAG addresses a major limitation of foundation models: their parameters are not a reliable, current database of organizational knowledge. Updating an index is often faster and safer than retraining a model. RAG can also provide citations, support access control, and reduce the need to expose all documents to the model at once. It does not, however, guarantee truth. If retrieval is incomplete, irrelevant, outdated, or unauthorized, the generated answer may still be wrong.

A robust RAG workflow includes document provenance, access-aware retrieval, chunking experiments, query rewriting, reranking, context-length management, citation generation, refusal behaviour, and evaluation. Retrieval metrics such as recall at k and precision at k assess whether useful evidence was found. Generation metrics and human review assess correctness, completeness, groundedness, clarity, and harmful content. Evaluation sets should include ordinary questions, ambiguous questions, adversarial prompts, out-of-scope requests, and questions whose answer is absent from the corpus.

Fine-tuning and RAG solve different problems. Fine-tuning changes model behaviour, style, or task capability using examples; RAG supplies changing or private knowledge at inference time. They may be combined, but fine-tuning is not a substitute for an authoritative knowledge base, and RAG is not a substitute for teaching a model a new reasoning behaviour in every case.

Responsible AI and Governance

Responsible AI translates ethical principles into controls, evidence, and accountable decisions. Fairness requires examining whether performance and error rates differ across relevant groups. A single aggregate accuracy figure can hide unequal false-positive or false-negative burdens. Fairness measures may conflict, particularly when base rates differ, so the appropriate criterion must be justified in context rather than selected mechanically.

Privacy protection begins with purpose limitation, data minimization, retention controls, access management, encryption, and careful treatment of personal or sensitive data. De-identification is not an absolute guarantee, especially when datasets can be linked. Prompts and retrieved documents may contain confidential information, and model providers may have different policies for retention and training use. These terms must be verified contractually and technically.

Security threats include prompt injection, data poisoning, model extraction, membership inference, adversarial inputs, insecure tools, and indirect prompt injection through retrieved documents. A RAG application must treat retrieved text as untrusted content, separate instructions from evidence, restrict tool permissions, validate outputs, and log relevant events without unnecessarily recording sensitive information.

Governance should assign owners for data, models, prompts, evaluation sets, endpoints, and incidents. A model card or system card can document intended use, limitations, training or retrieval sources, evaluation results, and known risks. High-impact uses may require human review, contestability, impact assessments, independent validation, and regulatory compliance. Human oversight is meaningful only when reviewers have authority, adequate information, time, and a realistic ability to override the system.

Illustrative Case: A University Knowledge Assistant

Background

A fictional university wishes to provide students with an assistant answering questions about enrolment, assessment rules, fees, library services, and academic integrity. Policies are distributed across web pages, PDF handbooks, and faculty documents. The university wants 24-hour access but cannot permit the assistant to invent regulations or expose information restricted to staff.

Situation and analysis

A general-purpose language model can produce fluent answers, but a standalone model may use outdated knowledge or hallucinate policy. A simple keyword search misses paraphrased questions. The problem therefore requires controlled retrieval, access management, evaluation, and escalation—not merely a chatbot interface.

Approach

The university establishes document ownership and approval dates. Public student-facing documents are collected into a governed repository, converted to text, divided into semantically coherent chunks, and indexed using both lexical and vector retrieval. Each chunk receives metadata for faculty, audience, effective date, and source URL. At query time, the system authenticates the student, applies access filters, retrieves candidate passages, reranks them, and prompts the model to answer only from the supplied evidence. Answers include links and effective dates. If evidence is missing or conflicting, the assistant states that it cannot determine the answer and directs the student to the responsible office.

A test set contains common questions, policy conflicts, misspellings, adversarial instructions, and questions outside the document collection. Evaluation examines retrieval recall, citation correctness, groundedness, refusal quality, latency, and accessibility. A human review process handles complaints and periodically samples conversations. The system does not make final decisions about disciplinary cases, admissions, or fee waivers.

Outcome

The illustrative design improves discoverability while preserving a route to authoritative human advice. Its quality depends less on fluent wording than on document governance, effective retrieval, access control, and monitoring. When a policy changes, updating and re-indexing the approved source is more appropriate than relying on users to correct the model.

Learning points

The case demonstrates that RAG is a systems architecture, not a prompt trick. It also shows why access control must operate before generation, why citations need verification, and why high-impact decisions should not be delegated to an unreviewed conversational model.

Challenges, Limitations, and Common Mistakes

Several recurring mistakes undermine large-scale AI projects. Teams may optimize an offline metric while ignoring business outcomes, leakage, subgroup performance, or operational latency. They may build a feature pipeline that cannot reproduce historical values, or deploy a model without a rollback mechanism. In generative AI, common failures include assuming a larger model is always better, measuring fluency instead of factuality, placing entire documents into prompts, ignoring authorization in retrieval, and treating a confident answer as evidence.

Cost is another constraint. Accelerator time, storage, data transfer, vector indexing, observability, and repeated experiments can create substantial expenditure. Cost-aware design includes workload scheduling, autoscaling limits, caching, model selection, quantization, prompt and context optimization, and deletion of unnecessary artifacts. Environmental effects should also be considered when comparing model size and retraining frequency.

Data and concept drift may invalidate a model even when infrastructure is healthy. Monitoring must connect changes in inputs to outcomes where labels become available. Alert thresholds should be actionable; excessive alerts produce fatigue, while silent failures permit harm. Finally, automation can amplify organizational bias or encode historical exclusion. Technical mitigation must be accompanied by process review and stakeholder participation.

Current Developments and Best Practices

Important developments include smaller and more efficient language models, open-weight models, multimodal systems, retrieval over structured and unstructured data, tool-using agents, synthetic-data workflows, confidential computing, and specialized inference hardware. Agentic systems can plan and call tools, but their expanded autonomy increases the need for permission boundaries, transaction confirmation, observability, and fail-safe design.

The following practices provide a durable foundation:

  • Begin with a measurable decision or user need rather than a model.
  • Establish data contracts, lineage, quality tests, and point-in-time correctness.
  • Separate experimentation from governed production promotion.
  • Evaluate technical performance, subgroup impact, cost, latency, robustness, and user outcomes.
  • Use access-controlled retrieval and authoritative sources for organizational knowledge.
  • Keep humans accountable for consequential decisions.
  • Design rollback, incident response, audit logging, and model retirement before launch.
  • Prefer the smallest model and context that meet the requirement.
  • Document assumptions, limitations, ownership, and change procedures.

Chapter Summary

Machine learning at scale is an engineered lifecycle involving data, features, distributed computation, deployment, monitoring, and governance. Scalable feature engineering requires contracts, partition-aware processing, point-in-time correctness, and training-serving consistency. Distributed training uses data, model, or pipeline parallelism, but communication, reproducibility, cost, and validation strategy determine its value. Inference may be batch, online, or streaming, each with distinct latency and operational requirements.

Cloud AI services accelerate implementation but introduce cost, portability, privacy, and vendor-dependence questions. Foundation models provide broad capabilities; embeddings and vector databases enable semantic retrieval. RAG connects models to current, private, and authoritative information, but its reliability depends on retrieval quality, access control, provenance, and evaluation. Responsible AI requires fairness analysis, privacy protection, security controls, transparency, human oversight, and accountable governance. The most effective AI systems align technical architecture with organizational purpose and risk.

Key Terms

Feature: An input variable supplied to a machine-learning model.

Feature engineering: The process of transforming raw data into useful model inputs.

Feature store: A system that manages, versions, and serves reusable features.

Target leakage: Use of information unavailable at prediction time during training.

Data parallelism: Distributed training in which workers process different data batches using model replicas.

Model parallelism: Splitting a model across multiple computing devices.

Inference: Generating a prediction or output from a trained model.

Model drift: Decline in model usefulness caused by changes after deployment.

Foundation model: A broadly pretrained model adaptable to many downstream tasks.

Embedding: A numerical vector representation of an object or piece of content.

Vector database: A system that indexes embeddings for similarity search.

Approximate nearest-neighbour search: Efficient similarity search that accepts a controlled approximation.

Retrieval-augmented generation: Generation supported by information retrieved from an external knowledge source.

Chunking: Dividing documents into smaller units for indexing and retrieval.

Reranking: Reordering retrieved results using a more precise scoring method.

Prompt injection: An attempt to manipulate a model through instructions in user or retrieved content.

Model registry: A controlled repository for versioned models and their metadata.

Canary deployment: Releasing a model to a small portion of traffic before wider deployment.

Point-in-time join: A historical join that uses only information available at a specified time.

Responsible AI: The design and governance of AI to promote fairness, safety, privacy, accountability, and transparency.

Review Questions

Short Answer Questions

1. Why is training-serving consistency important in a feature store?

2. Distinguish data drift from concept drift.

3. What is the purpose of a model registry?

4. Why can vector search not replace a relational database in every application?

5. State two security risks associated with generative AI systems.

Long Answer Questions

1. Explain the architecture and operational requirements of a distributed machine-learning lifecycle.

2. Compare batch, online, and streaming inference, including suitable use cases and risks.

3. Explain how a RAG system is constructed from document ingestion through answer evaluation.

4. Discuss the advantages and limitations of managed cloud AI services compared with self-managed platforms.

5. Explain how responsible AI principles can be converted into practical governance controls.

Analytical / Application Questions

1. A bank’s loan model reports excellent accuracy, but its production performance declines after a major economic change. Diagnose possible causes and propose a monitoring and retraining strategy.

2. Design a RAG architecture for an organization holding confidential documents across several departments. Specify retrieval, authorization, evaluation, and audit controls.

3. An organization must choose between a large proprietary model accessed through an API and a smaller open model deployed privately. Develop a decision framework covering quality, cost, latency, privacy, portability, and risk.

22. Multiple Choice Questions with Answers

Question 1

Which design most directly prevents target leakage in a time-dependent prediction problem?

A. Using a larger neural network

B. Constructing features only from events available before the prediction cutoff

C. Increasing the training batch size

D. Removing the validation dataset

Correct Answer: B. Constructing features only from events available before the prediction cutoff

Question 2

In data parallelism, what is generally replicated across workers?

A. Only the raw data schema

B. The model, while workers process different data batches

C. Only the model registry

D. The prediction endpoint URL

Correct Answer: B. The model, while workers process different data batches

Question 3

Which inference pattern is most appropriate for generating a nightly risk score for every customer?

A. Batch inference

B. Synchronous online inference for every user request

C. Prompt injection

D. Model parallelism

Correct Answer: A. Batch inference

Question 4

Why are point-in-time joins used when constructing historical training features?

A. To increase the number of model parameters

B. To ensure features reflect information available at the historical prediction time

C. To convert vectors into relational tables

D. To eliminate the need for labels

Correct Answer: B. To ensure features reflect information available at the historical prediction time

Question 5

What is the principal role of an embedding in a RAG system?

A. To encrypt every document permanently

B. To represent content numerically so semantically related items can be retrieved

C. To replace access-control policies

D. To guarantee that generated answers are factual

Correct Answer: B. To represent content numerically so semantically related items can be retrieved

Question 6

Which statement best describes retrieval-augmented generation?

A. It retrains the foundation model after every user question

B. It retrieves relevant external information and supplies it to a generative model

C. It removes the need for document governance

D. It uses only exact keyword matching

Correct Answer: B. It retrieves relevant external information and supplies it to a generative model

Question 7

A vector database retrieves a relevant document from the wrong department. Which control is most directly required?

A. Metadata-based access filtering before generation

B. Increasing the temperature of the model

C. Deleting the model registry

D. Using a larger output vocabulary

Correct Answer: A. Metadata-based access filtering before generation

Question 8

Which deployment strategy sends a new model to a small fraction of production traffic before a full release?

A. Shadow deployment

B. Canary deployment

C. Offline feature computation

D. Data parallelism

Correct Answer: B. Canary deployment

Question 9

Why can aggregate accuracy be inadequate for responsible AI evaluation?

A. Accuracy is always unrelated to prediction quality

B. It may conceal unequal error rates or harms across population groups

C. It measures only infrastructure latency

D. It automatically reveals model explanations

Correct Answer: B. It may conceal unequal error rates or harms across population groups

Question 10

A retrieved document contains instructions telling the model to ignore system rules and disclose confidential data. What threat does this illustrate?

A. Feature normalization

B. Prompt injection through retrieved content

C. Point-in-time correctness

D. Canary release

Correct Answer: B. Prompt injection through retrieved content

Big Data and Cloud Analytics
Chapter 10 of 15