ML System Design · Module 25 of 47 · 12 concepts · about 14 min

Responsible ML: Fairness, Privacy and Security

The obligations every production model carries: where unfair outcomes come from and how to measure and reduce them, protecting personal data in training and serving, the attacks ML systems face and their defences, and the human oversight and laws that apply.

At work: Increasingly a launch requirement rather than an extra, especially for models that decide about people: credit, hiring, insurance, moderation, pricing and fraud.

Why this is part of the design

What it is

A model that decides about people can harm them in ways ordinary bugs do not:

  • unfairly: worse outcomes for some groups, often without anyone intending it;
  • invasively: revealing or misusing personal data;
  • unsafely: being manipulated by attackers;
  • without recourse: no explanation, no appeal, no human to ask.

These are design requirements, decided with the other requirements, not checked at the end.

Why it matters

Fixing them late is expensive and sometimes impossible.

  • A model trained on data it should not have used may have to be discarded.
  • Laws increasingly require assessments, documentation and human oversight before launch.
  • Trust, once lost publicly, is very hard to win back.

In the real world: Amazon reportedly scrapped an experimental hiring model in 2018 after finding it penalised CVs mentioning women's organisations, learned from a decade of mostly male hires.

Assuming a model is fair because it does not use sensitive attributes like gender or religion. Other features (postcode, device, name, shopping patterns) can stand in for them.

Where unfairness comes from

What it is

Bias usually enters through the data and the setup, not the algorithm:

  • historical bias: past decisions were unfair, and labels record them;
  • representation: some groups have little data, so the model is worse for them;
  • measurement: labels or features mean different things for different groups (fewer reports in areas with less checking);
  • proxies: features that correlate with a sensitive attribute;
  • feedback loops: decisions that generate more data about some groups (module 22).

Why it matters

Knowing the source tells you the fix.

  • Representation problems need more data or group-aware evaluation.
  • Historical bias in labels needs a rethink of what is being predicted.
  • Proxy problems need feature review and testing, not just removing one column.

In the real world: A widely cited 2019 study found a US healthcare algorithm under-referred Black patients because it predicted future healthcare cost, which reflected unequal access, rather than illness itself.

Treating fairness as only a modelling problem. If the label itself encodes past unfairness ('was hired'), a perfectly accurate model reproduces it.

Measuring fairness

What it is

Compare outcomes across groups. Common measures:

  • selection rate (demographic parity): are groups flagged or approved at similar rates?
  • true positive rate (equal opportunity): of those who really are positive, is the same share caught in each group?
  • false positive rate: of those who are really negative, is the same share wrongly flagged?
  • precision and calibration by group: does a score mean the same thing in each group?

Mathematically, these usually cannot all be equal at once when groups' base rates differ. Choosing which matters most is a decision for the business, with legal and ethical input.

Why it matters

Measuring is the first step, and it is cheap.

  • Report the measures per group alongside accuracy for every release.
  • Large gaps are a signal to investigate, not automatically proof of unfairness, but they must be explained.

In the real world: Kirana Kart reports fraud-model precision, recall and false-positive rate per city on every release, after finding a newly launched city's honest customers were flagged five times as often.

Visual example

Computed

One fraud model, one threshold, two groups of customers. Honest customers in the new city are wrongly flagged about five times as often.

Illustrative counts. The new city has less training data.
groupordersflag ratefraud caught (recall)flags that were fraud (precision)honest customers flagged
Established cities8,0002.5%75%30%1.8%
Newly launched city2,00010%50%10%9.2%

Reporting one fairness number as if it settled the question. A model can have equal selection rates while wrongly flagging one group's honest members far more often.

Reducing unfairness

What it is

Interventions at three stages:

  • Before training: collect more data for under-represented groups; fix biased labels; re-weight examples; review and remove proxy features.
  • During training: add a fairness constraint or penalty to the objective.
  • After training: adjust thresholds or calibration per group, where law allows; add human review for borderline cases.

Then measure again: an intervention can shift the problem elsewhere.

Why it matters

Data fixes are usually the most durable.

  • A model that is simply worse for a group because it has seen too little of it improves with more and better data.
  • Post-processing is quick but must be legally checked: in some domains, treating groups differently by rule is itself prohibited.

In the real world: Kirana Kart reduced the new city's false-positive rate by adding a 'city age' feature, collecting reviewer labels there for a month, and routing its borderline cases to human review rather than automatic blocking.

Removing the sensitive attribute and declaring the job done. Without measuring outcomes by group, you cannot know whether proxies are doing the same work.

Privacy risks in ML

What it is

Models create privacy risks beyond the raw data:

  • re-identification: 'anonymous' data with enough details (location history, purchase patterns) can identify people;
  • memorisation: models, especially large ones, can memorise and reveal rare training examples;
  • membership inference: attackers can sometimes tell whether a person's record was in the training data;
  • inference of sensitive traits: a model can infer health, pregnancy or finances from purchases.

Why it matters

Privacy laws apply to these risks, not only to stored records.

  • Removing names is not anonymisation; combinations of ordinary fields often identify people.
  • Inferring a sensitive trait can be as harmful as collecting it.

In the real world: Researchers showed that four location points were enough to uniquely identify most people in a large mobile-phone dataset, which is why location data is treated as highly sensitive.

Calling a dataset anonymous because IDs were hashed. A hashed ID that is consistent across tables is still a key that links everything about a person.

Privacy-preserving techniques

What it is

Techniques that reduce privacy risk:

  • minimisation and aggregation: use only what is needed; prefer aggregates over raw records;
  • pseudonymisation with keys held separately, and strict access control;
  • differential privacy: add carefully calibrated noise so no single person's data changes results much; used in statistics and training (DP-SGD);
  • federated learning: train on users' devices and send only model updates, not data;
  • on-device inference: keep data on the phone (module 18).

Why it matters

They allow useful models with less exposure.

  • Each has costs: differential privacy reduces accuracy, especially for small groups; federated learning is complex to run.
  • The right mix depends on how sensitive the data is and what the law requires.

In the real world: Apple and Google use differential privacy to learn usage statistics, and Google's phone keyboard uses federated learning so typing data stays on the device.

Adding differential privacy with a large privacy budget and claiming strong protection. The guarantee depends on the parameters; a loose budget gives little real protection.

Deletion and models

What it is

When a user asks for their data to be deleted, it must leave:

  • raw data, feature tables and training sets;
  • feature-store values and caches;
  • and, in principle, influence on trained models.

Practical approaches: delete from all stores promptly, and retrain on the cleaned data on a regular schedule, so models stop reflecting deleted users within a known time. Research on 'machine unlearning' aims to remove one person's influence without full retraining.

Why it matters

Laws such as GDPR and India's DPDP Act give people rights over their data.

  • Lineage (module 8) is what makes finding every copy possible.
  • Regular retraining already in place makes compliance much simpler.

In the real world: Kirana Kart records deletion requests in a table that every training pipeline joins against, so deleted users are excluded from the next nightly retrain.

Deleting from the production database but not from training snapshots. The next retrain brings the deleted user's data straight back into the model.

Practise it: Design a Recommendation System, Design a Search Ranking System

Attacks on ML systems

What it is

ML systems face specific attacks:

  • evasion: crafting inputs to fool the model (fraudsters tuning behaviour to stay under the score; tiny changes to images);
  • data poisoning: injecting bad examples into training data (fake reviews, coordinated clicks, false reports);
  • model extraction: querying a model many times to copy it or learn its decision boundary;
  • supply-chain attacks: malicious model files or libraries (module 20);
  • inference attacks: extracting private training data (above).

Why it matters

Any model that affects money, access or reputation will be attacked.

  • Fraud, spam, moderation and ranking (search and reviews) are constant targets.
  • Attacks exploit the same openness that makes ML useful: it learns from data that attackers can influence.

In the real world: Microsoft's Tay chatbot was manipulated within a day in 2016 by users feeding it offensive content, a well-known example of poisoning through live learning.

Training on user-generated signals with no defence against manipulation. A ranking model that learns from clicks will be gamed by click farms.

Defences

What it is

Defend in layers:

  • hard-to-fake features: device, network, behaviour over time, rather than easily changed fields;
  • rate limits and anomaly detection on queries and on training signals;
  • data provenance and filtering: trust weights for sources; remove coordinated or bot activity before training;
  • limited exposure: return decisions, not raw scores; avoid revealing exact reasons to suspected attackers;
  • adversarial testing (red-teaming) before launch and regularly after;
  • human review for high-stakes or uncertain cases.

Why it matters

No single defence is enough against a motivated attacker.

  • Layers raise the cost of attack until it is not worth it.
  • Monitoring for sudden changes (module 21) catches attacks the defences miss.

In the real world: Kirana Kart's review-ranking model ignores ratings from accounts less than a week old or with no purchases, and down-weights bursts of similar reviews, after a seller tried buying fake reviews.

Returning precise probability scores to every caller. Detailed scores make it much easier to probe and copy the model or tune an attack.

Human oversight and regulation

What it is

High-stakes decisions need people and processes around the model:

  • human review of borderline or high-impact cases;
  • explanations to affected people, and a way to appeal to a human;
  • impact assessments before launch for risky uses;
  • documentation: model cards, data sheets, decision logs.

Laws are converging on these: the EU AI Act sets duties by risk level (with some uses banned and 'high-risk' uses such as credit and hiring heavily regulated); India's DPDP Act governs personal data; sector rules apply to banks, insurers and health.

Why it matters

Regulation turns good practice into obligation.

  • Designing review queues, explanations and logs in from the start is far cheaper than retrofitting them.
  • Human review also improves the model: reviewers' decisions are high-quality labels.

In the real world: Kirana Kart never permanently bans an account on the model's decision alone; a reviewer confirms each ban with the top reasons shown, and customers can appeal through support.

Visual example

Oversight

The model narrows; people decide the hard cases.

A high-stakes decision with oversight built in

  1. Model scoresProbability and top reasons
  2. PolicyClear cases automated; borderline to review
  3. Human reviewSees reasons; can overturn
  4. Explain and appealCustomer can ask a person
  5. LearnOutcomes become labels

A 'human in the loop' who approves hundreds of decisions an hour without the information to disagree. Oversight needs time, context and authority to overturn the model.

Interview questions: responsible ML

What it is

The questions interviewers ask about responsible ML, from the first screening call to the senior round. Cover the answer, say yours aloud, then compare.

Why it matters

Reading an idea and explaining it are different skills.

  • Each answer below is the two or three sentences an interviewer is listening for.
  • The reasoning behind each one is in the cards above. If an answer surprises you, go back to that card.

In the real world: Fairness and safety questions now appear in most senior ML interviews, especially for credit, hiring, moderation and marketplace roles.

Q: How would you check a model for fairness?

Define the groups that matter, then compare selection rate, true and false positive rates, precision and calibration across them on held-out data, investigate large gaps, and repeat on every release.

Q: Why is removing sensitive attributes not enough?

Other features act as proxies, and labels may encode past unfairness. Outcomes must be measured by group to know whether the model treats groups differently.

Q: Can a model satisfy all fairness measures at once?

Generally not when groups have different base rates; equal selection, equal error rates and equal calibration conflict. The choice of which to prioritise is a business, legal and ethical decision.

Q: How do you protect privacy in an ML system?

Minimise and aggregate data, pseudonymise with separate keys and strict access, honour deletion through lineage and regular retraining, and use differential privacy, federated learning or on-device inference where sensitivity demands.

Q: What attacks do ML systems face?

Evasion, data poisoning, model extraction, supply-chain attacks and inference attacks on training data.

Q: How would you defend a fraud or ranking model from manipulation?

Hard-to-fake features, rate limits and anomaly detection, filtering and trust-weighting training signals, not exposing raw scores or exact reasons, red-teaming, and human review for high-stakes cases.

Answering fairness questions with 'we remove protected attributes'.

Exercise: audit a model

What it is

A short build that uses this module's ideas. Write it yourself before looking anything up; the checks at the end tell you whether it works.

Why it matters

An idea you have only read fades in a week.

  • Building it once, even in fifty lines, is what makes it yours.
  • Interviewers can tell the difference between someone who has read about a loop and someone who has debugged one.

In the real world: Model audits like this are part of launch reviews for regulated models at banks and insurers.

Your task. Audit a classifier for fairness and privacy risks and write a short model card with your findings.

Steps

  1. Use a public dataset with a group attribute, such as the UCI Adult income dataset.
  2. Train a model without the group attribute.
  3. Compute selection rate, true and false positive rates, and precision per group.
  4. Find which remaining features best predict the group attribute (proxies).
  5. Try one mitigation (re-weighting, or per-group thresholds) and re-measure all metrics, overall and per group.
  6. List three privacy risks of the dataset and one defence for each, then write a one-page model card.

You are done when

  • You have a per-group table before and after mitigation, and can state what improved and what got worse.
  • You have named at least two proxy features.
  • Your model card states intended use, limitations and per-group performance.

Stretch. Use Fairlearn or AIF360 to repeat the analysis and compare with your own numbers.