Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

Learning path · 16 steps

End-to-End ML Use Cases: Fraud, Recommendations, Forecasting and Ticket Routing
  1. 1
    Fraud Scoring, Part 1: The Problem, the Metric and the Baseline
  2. 2
    Fraud Scoring, Part 2: Training With Time Splits, Leak-Free Features and a Cost-Picked Threshold
  3. 3
    Fraud Scoring, Part 3: Serving It With FastAPI, Docker and a 50 ms Budget
  4. 4
    Fraud Scoring, Part 4: Release and Monitoring With Shadow, Drift and Late Labels
  5. 5
    Recommendations, Part 1: Two Stages, Candidates Then Ranking
  6. 6
    Recommendations, Part 2: Candidate Generation With Embeddings
  7. 7
    Recommendations, Part 3: The Ranker and Offline Metrics (Recall@k and nDCG)
  8. 8
    Recommendations, Part 4: Serving With FastAPI, a Cache and a Popular Fallback
  9. 9
    Demand Forecasting, Part 1: The Business Problem, a Price per Mistake and the Line to Beat
  10. 10
    Demand Forecasting, Part 2: Walk-Forward Backtesting, Ridge vs Boosting and the Slices an Average Hides
  11. 11
    Demand Forecasting, Part 3: The Nightly Batch Pipeline That Survives a Crash
  12. 12
    Demand Forecasting, Part 4: Serving the Forecasts, the Outcome Join and a Retrain Rule
  13. 13
    Ticket Routing, Part 1: A Safe Split, Keyword Rules and a TF-IDF Baseline
  14. 14
    Ticket Routing, Part 2: Fine-Tuning a Small Encoder on a CPU, With a Run Log and Honest Ranges
  15. 15
    Ticket Routing, Part 3: Quantise to int8, Host Behind FastAPI and Measure the Server
  16. 16
    Ticket Routing, Part 4: Canary, Automatic Rollback and "Does Your Small Model Reason?"
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. End-to-End Use Cases

Learning path: End-to-End ML Use Cases: Fraud, Recommendations, Forecasting and Ticket Routing · Step 16 of 16

Ticket Routing, Part 4: Canary, Automatic Rollback and "Does Your Small Model Reason?"

Release the int8 ticket router in stages: 10%, 50%, then everyone, with a floor of stable accuracy minus 0.05: int8 goes through, and a simulated 2-bit model scoring 0.179 on its first 28 tickets is rolled back. Then 24 hand-written probes test the claim that it reasons: 8/8, 5/8, 5/8.

Chaand Sheikh

·27 November 2026End-to-End Use Cases

What you will learn

  • Send a candidate model a stable, hashed slice of tickets at 10%, 50% and 100%
  • Write a canary verdict with a margin and a minimum count, and roll back automatically
  • Test whether a small classifier reasons with hand-written behaviour probes
  • Answer the interview question without overclaiming

Before you start

  • Ticket Routing, Part 3: Quantise to int8, Host Behind FastAPI and Measure the Server
  • Shadow, Canary and Rollback: Releasing a New Model Without Betting Everything on It

We have a smaller model from Part 3: the int8 ticket router. Today we decide how it takes over from the fp32 one. We won't switch it on for everyone. It gets a small slice of the tickets first (a canary), and if it's bad, it's rolled back on its own. Then a question you'll get in interviews: if you train a small model, does it reason? We won't just give an opinion. We'll test it.

The tickets are synthetic: validation tickets from the 8,000-ticket set, replayed as traffic. The 2-bit candidate is simulated rounding, and the margin of 0.05 is a choice for this project.

One quiet route first

You don't hand a new bus driver the busiest route on day one. You give them one quiet route while the experienced drivers keep running everything else, and you watch how it goes side by side. If it goes well, they get more routes. If it doesn't, they come off the road, and only that one route was affected.

One honest note. I know the right queue for every ticket here, because I'm replaying validation tickets. In production that answer comes later, usually when an agent moves a ticket to another queue. So your evidence arrives late. (When Labels Arrive Weeks Late deals with exactly that.)

The canary in code: canary.py

"""Canary: send a slice of traffic, watch, roll back."""
import json
import zlib


def arm(ticket_id, pct):
    """Same ticket always lands in the same arm."""
    h = zlib.crc32(str(ticket_id).encode()) % 100
    return "cand" if h < pct else "stable"


def set_live(path, name):
    with open(path, "w") as f:
        json.dump({"live": name}, f)


def run_canary(rows, stable, cand, stages,
               min_n=15, margin=0.05):
    """stages: [(percent, tickets)]. Predictions are dicts
    ticket id -> queue. Rolls back on a bad stage."""
    log, pos = [], 0
    for pct, size in stages:
        hits = {"stable": [], "cand": []}
        for r in rows[pos:pos + size]:
            a = arm(r["id"], pct)
            p = (cand if a == "cand" else stable)[r["id"]]
            hits[a].append(p == r["label"])
        pos += size
        acc = {k: sum(v) / len(v) if v else 0.0
               for k, v in hits.items()}
        n = len(hits["cand"])
        floor = acc["stable"] - margin
        bad = n >= min_n and acc["cand"] < floor
        log.append({"pct": pct, "n_cand": n,
                    "cand_acc": round(acc["cand"], 3),
                    "stable_acc": round(acc["stable"], 3),
                    "n_stable": len(hits["stable"]),
                    "verdict": "ROLLBACK" if bad
                    else "ok"})
        if bad:
            return log, "stable"
    return log, "cand"
  • arm hashes the ticket id and takes it modulo 100. Under the percentage means candidate. So the same ticket always lands in the same arm.
  • run_canary takes the next batch for each stage, finds each ticket's arm, takes that arm's answer and records right or wrong.
  • The floor is stable accuracy minus a margin of 0.05, because a small slice is noisy.
  • The verdict is bad only if the candidate is under the floor and has at least 15 tickets. With fewer, we don't decide anything.
  • If it's bad, the function returns stable straight away, and later stages never run. The winner's name goes into a small JSON file, so a rollback is one small file changing.

The stages in run.py are [(10, 200), (50, 200), (100, 137)]: 537 validation tickets in three batches.

int8 goes through

candidate int8
  {'pct': 10, 'n_cand': 28, 'cand_acc': 0.857, 'stable_acc': 0.901, 'n_stable': 172, 'verdict': 'ok'}
  {'pct': 50, 'n_cand': 108, 'cand_acc': 0.861, 'stable_acc': 0.837, 'n_stable': 92, 'verdict': 'ok'}
  {'pct': 100, 'n_cand': 137, 'cand_acc': 0.876, 'stable_acc': 0.0, 'n_stable': 0, 'verdict': 'ok'}
  live now: {"live": "int8"}
  • 10%: 28 tickets land on the candidate. It scores 0.857, stable scores 0.901, so the floor is 0.851. It passes by a hair.
  • 50%: 108 tickets. Candidate 0.861, stable 0.837. It's flipped, with the same model. That's noise, and that's why the margin exists.
  • 100%: candidate 0.876. Stable shows 0.0 on 0 tickets; that zero means nothing, the arm is just empty. int8 is promoted.

One honest catch: this check only looks at accuracy. It never saw that int8 was slower and used more memory in Part 3, so those need a check of their own.

The 2-bit model gets caught

candidate 2 bit
  {'pct': 10, 'n_cand': 28, 'cand_acc': 0.179, 'stable_acc': 0.901, 'n_stable': 172, 'verdict': 'ROLLBACK'}
  live now: {"live": "fp32"}

Because the hash is stable, it's the same 28 tickets at 10%. The candidate scores 0.179 against a floor of 0.851, and 28 is more than 15, so the verdict is rollback. It stops right there: the 50% and 100% stages never run, and the file flips back to fp32.

Canary stages for two candidates int8 10%: 0.857 ok 50%: 0.861 ok 100%: 0.876 ok live: int8 2 bit 10%: 0.179 50%: never run 100%: never run live: fp32 floor 0.851, n = 28
Floor = stable accuracy (0.901) minus the 0.05 margin. A bad stage ends the release.

Of those 28 tickets, 5 were right and 23 went to the wrong queue. The other 172 went through stable as usual. So a rollback isn't the system failing. It's the system doing its job. The general pattern, with a shadow stage before the canary, is in Shadow, Canary and Rollback.

Does it reason?

An interviewer asks: you trained a small model, so does it reason? Look at what training actually changed. Some weights moved, so that ticket text maps to one of four outputs. It can't explain anything, because it has no way to say anything except four words. Ask it something silly:

off topic: 'what is two plus two' -> shipping 0.38
off topic: 'write me a poem about rain' -> shipping 0.33

Shipping, both times. It can't say "this isn't a ticket".

A small test for reasoning: probe.py

An opinion isn't a test. So probe.py has three groups of hand-written tickets, eight in each. I wrote them before running it, and I didn't change them afterwards. Eight per group is tiny on purpose: it's a behaviour check, not a benchmark. A few of them:

PROBES = {
    "seen words": [
        ("refund and invoice", "billing"),
        ("parcel and tracking number", "shipping"),
        # ... 8 in total
    ],
    "two topics, one ruled out": [
        ("no refund needed, I cannot sign in", "login"),
        ("the parcel is fine, the app crashes", "technical"),
        # ... 8 in total
    ],
    "needs a step of thought": [
        ("my bank shows two entries for one order",
         "billing"),
        ("I changed phones so the text goes to my old "
         "number", "login"),
        # ... 8 in total
    ],
}

python probe.py on the same seed-0 model:

seen words                 8/8
two topics, one ruled out  5/8
  miss: 'the parcel is fine, the app crashes' want technical, got shipping
  miss: 'invoice is correct, delivery late' want shipping, got billing
  miss: 'not a login problem, wrong address' want shipping, got login
needs a step of thought    5/8
  miss: 'I changed phones so the text goes to my old number' want login, got shipping
  miss: 'it keeps asking who I am and rejects what I type' want login, got shipping
  miss: 'the numbers are from last week however often I refresh' want technical, got shipping
  • Seen words, 8/8. Good: the model works on what it trained on.
  • Two topics, one ruled out, 5/8. "The parcel is fine, the app crashes" gets shipping. It grabs the word parcel and misses the point.
  • Needs a step of thought, 5/8. "I changed phones so the text goes to my old number" is login, and it says shipping.

Five out of eight isn't proof of reasoning, and it isn't proof against it. A hit could be word association: in "my bank shows two entries", the word bank alone might carry it.

The answer in an interview

  1. The direct answer. No, I wouldn't say it reasons. Training fitted a mapping from text to labels, on my tickets.
  2. The test. I'd write behaviour probes where the right answer needs logic and not a keyword, keep them apart from training, and report them as their own slice.
  3. The limit. A small probe set only shows what happened on those tickets, and passing doesn't prove reasoning either.

Follow-ups you might get. What if all the probes pass? Then write harder ones. Would a bigger model reason? I'd run the same kind of test on it before claiming anything. We haven't run a bigger model here, so there's no result to quote.

Common mistakes

  • Switching everyone at once. A canary limits the damage to one slice: 28 tickets here.
  • Deciding on too few tickets. min_n stops a verdict on a handful of rows.
  • No margin. The same int8 model was below stable at 10% and above it at 50%. Without a margin, noise rolls back good models.
  • Checking only accuracy. The canary promoted int8 without seeing its memory and latency.
  • Claiming reasoning from a good score. 8/8 on seen words says nothing about thinking; test with probes.

Recap

CheckResult
Canary, int810%, 50%, 100% all ok, promoted (accuracy only)
Canary, 2 bit (simulated)0.179 against a floor of 0.851 on 28 tickets: rolled back; 172 tickets unaffected
Off-topic inputsshipping (0.38) and shipping (0.33)
Probesseen words 8/8, one ruled out 5/8, a step of thought 5/8

Try it yourself: add three tricky tickets of your own to PROBES in probe.py. Guess each answer first, then run it.

That completes the ticket routing use case: a safe split and baselines, a fine-tuned small encoder, int8 behind FastAPI, and the staged release above.

Keep going in the learning path End-to-End ML Use Cases: Fraud, Recommendations, Forecasting and Ticket Routing · step 16 of 16

Previous
Ticket Routing, Part 3: Quantise to int8, Host Behind FastAPI and Measure the Server
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)

Related posts

Project: Car Price Predictor End to End, from CSV to a FastAPI Price API

The whole ML workflow on 205 cars: clean the brand out of CarName, split first, audition five regressors on the same folds, tune the random forest, test once (RMSE 2,195, R2 0.939), save it and serve prices with FastAPI.

Fraud Scoring, Part 1: The Problem, the Metric and the Baseline

Before training a fraud model, write down what good means. On 6,000 synthetic validation transactions, a rule that never flags is 96.13% accurate and costs 23,200, flagging everyone costs 28,840, and a small contract.py fixes the rules first.

Fraud Scoring, Part 2: Training With Time Splits, Leak-Free Features and a Cost-Picked Threshold

Train the fraud model against its contract: a time split of 30,000 synthetic transactions, a card_n_1h feature that never looks ahead, XGBoost that pays 23,200 at 0.5, and a cost-picked threshold of 0.045 that brings validation to 14,955 and test to 16,765.

Fraud Scoring, Part 3: Serving It With FastAPI, Docker and a 50 ms Budget

A payment is waiting on the fraud score. Time each stage (the model takes 0.43 ms of a 3.3 ms request), then load test: p99 is 6.1 ms with one client and 163.3 ms with 32, against an example 50 ms budget. Then a Dockerfile, built and run once.

On this page

  • One quiet route first
  • The canary in code: canary.py
  • int8 goes through
  • The 2-bit model gets caught
  • Does it reason?
  • A small test for reasoning: probe.py
  • The answer in an interview
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.