On-Device Face Unlock for a Mobile Banking App at Scale
Machine LearningModel answerLast updated
Design a privacy-preserving, on-device face authentication system for a mobile app with tens of millions of users, covering models, evaluation, spoofing defenses, fairness, offline use and rollout.
You are asked to design a face-based authentication feature for a mobile banking app with 50 million monthly active users. Network access on user devices is unreliable, so the feature must keep working when the phone is offline.
Describe an end-to-end design that covers the following:
- Task framing. Should the system do 1:1 verification or 1:N identification? Justify the choice.
- Model and embedding. Pick a model family and embedding size suitable for mid-tier phones. Say which training objective you would use (for example, an angular-margin loss versus a triplet loss) and why. Describe the scale of training data and the augmentations.
- Evaluation. Define the protocol (ROC/DET, impostor selection, confidence intervals) and propose target operating points, for example FAR ≤ 0.001 at TPR ≥ 0.98 for routine unlock.
- Spoofing and robustness. Explain how you handle presentation attacks (2D, 3D, IR-assisted), replay and camera-injection attacks, and occlusions such as masks and glasses.
- Fairness. Explain how you check for and reduce performance gaps across demographic groups, including whether per-cohort thresholds are appropriate.
- Privacy and security. Cover template storage, template protection, user opt-out, and the role (if any) of differential privacy.
- Resource budget. Target p95 latency under 150 ms, memory under 50 MB, and a small per-authentication battery cost. Show how the pipeline fits.
- Deployment location and offline behavior. Decide between on-device and server inference, and say what happens when the device has no connectivity.
- Operations. Describe drift monitoring, periodic re-enrollment, and how you would safely A/B test changes (shadow mode, guardrails).
State your assumptions and call out the key trade-offs.
Hints
Hint 1
Ask who is claiming an identity. If the app already knows which account is logged in, consider what that implies for the matching problem, the error rates, and where biometric data needs to live.
Hint 2
Do a quick budget: split 150 ms across detection, quality check, liveness, embedding and matching, and note which stages can run on an NPU. Then think about why a smaller embedding can be acceptable after distillation.
Hint 3
Treat the face match as a local gate that unlocks a hardware-backed key, and let the server verify a signed, nonce-bound assertion instead of ever seeing a face. Then think about how you would roll out safely: shadow mode first, then a staged ramp with guardrails on false rejects, fallback rate, and per-cohort error.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and assumptions
- Use case: unlocking the banking app and authorizing step-up actions such as payments. The claimed identity is known: it is the logged-in account bound to this device.
- Load: 50M MAU at roughly 2 authentications per day is about 100M per day, around 1.2k/s on average and perhaps 5k/s at peak. Matching is local, so the server only verifies signed assertions.
- Targets:
- Routine unlock: FAR ≤ 1e-3 at TPR ≥ 0.98.
- High-risk actions: FAR ≤ 1e-5 at TPR ≥ 0.95, with PIN fallback.
- Device budget (mid-tier phone): p95 < 150 ms, peak memory < 50 MB, and a very small battery cost per attempt.
2. Verification, not identification
Choose 1:1 verification. The account is already known, so the only question is whether this face matches the enrolled template.
1:N identification is the wrong choice because:
- False matches grow roughly with N × FMR, so a 50M gallery would need an impractically low per-comparison FMR.
- It requires a central biometric database, which is a breach target and a heavy compliance burden (GDPR Art. 9, BIPA, CCPA).
- It needs the network on every attempt, which breaks offline use.
3. Architecture
On-device pipeline, int8 models, NPU with GPU fallback:
| Stage | Model | Size | p95 |
|---|---|---|---|
| Detection + landmarks | BlazeFace / RetinaFace-mobile | ~1 MB | 15 ms |
| Alignment + quality gate | analytic + tiny CNN | <0.5 MB | 5 ms |
| Passive liveness | MobileNetV3-small (+IR/depth when present) | ~2 MB | 30 ms |
| Embedding | MobileFaceNet-class, 128-d, L2-normalized | ~4 MB | 40 ms |
| Match | cosine vs. 1–3 templates | n/a | <1 ms |
Total is about 90 ms, which leaves headroom for camera warm-up and slower devices. Peak memory is around 30 MB including runtime and frame buffers.
Why 128-d: after distillation it typically loses very little accuracy versus 512-d, the template is only 128 bytes at int8, and a stolen template reveals less.
Battery: open the camera only on an explicit trigger, stop as soon as a decision is reached, and process frames only until a couple of consecutive frames pass the quality gate.
Credential flow (FIDO-style):
- Server issues a nonce.
- Local face match succeeds.
- That unlocks a hardware-backed key (Secure Enclave / StrongBox).
- The device signs the nonce, timestamp, action and an attestation token.
- The server verifies the signature and attestation.
The server trusts a key, never a face.
4. Training
- Loss: an angular-margin softmax (ArcFace, s≈64, m≈0.5). It trains like classification, needs no hard-negative mining, and gives tight angular clusters that matter at low FAR. Triplet loss depends heavily on mining and scales badly with data. For noisy or huge identity sets use sub-center variants or partial-FC.
- Distillation and quantization: train a large teacher, distill into the mobile student with embedding and logit losses, then apply quantization-aware training.
- Data: millions of images across at least ~100k identities, consented and properly licensed, with synthetic identities to fill demographic gaps. Avoid scraped data of unclear provenance. Balance by skin tone, age and gender.
- Augmentation: synthetic masks, glasses and hats, low light and backlight, motion blur, compression, yaw up to about ±45°, and camera-specific color pipelines.
- Occlusion: mask-aware training, an optional second consented template, and a quality gate that asks the user to adjust instead of silently rejecting.
5. Evaluation
- Use a held-out set of disjoint identities. Report ROC and DET plus TAR at FAR = 1e-3, 1e-4 and 1e-5.
- Statistical power: by the rule of three, zero errors in 3/FAR trials only bounds FAR at the 95% level, so use 10–100× that many impostor pairs. Bootstrap over identities, not pairs, because pairs from the same person are correlated.
- Use hard impostors (same demographic, relatives, lookalikes). Random impostors make FAR look better than reality.
- Liveness: follow ISO/IEC 30107-3 and report APCER and BPCER per attack type (print, screen replay, 3D mask, injection). Example targets: APCER ≤ 1%, BPCER ≤ 3%.
- Slice by device tier, camera, lighting, and demographic cohort.
6. Liveness and security
- Passive RGB liveness by default, an active challenge (blink, head turn) for high-risk or low-confidence cases, and IR or depth where hardware allows, which largely removes 2D attacks.
- Injection and replay: device attestation, root and hook detection, server nonces, short TTLs, single-use assertions.
- Template protection: encrypt with a key in secure hardware, never back up or sync, and optionally use a cancelable per-device transform so a leaked template can be revoked.
- Rate limits: after about 5 failures, require PIN and trigger account-level risk checks.
7. Fairness
- Measure FAR and FRR per cohort, not just overall. Gaps often show up in impostor scores, so check both.
- Prefer fixing the model and data (rebalancing, synthetic data, hard-example mining) over per-cohort thresholds. A single global threshold keeps the security guarantee uniform. If you calibrate by cohort, do it only to equalize FAR, require legal sign-off, and avoid inferring protected attributes on the device.
- Gate releases on a maximum allowed cohort gap.
8. Privacy
- Templates and raw frames stay on the device and are deleted on opt-out or logout. Offer PIN as an equal alternative.
- Differential privacy is mainly relevant to any telemetry or federated training. Send only aggregated, noised metrics, never images or embeddings.
9. Offline behavior
- Matching is local, so it works offline.
- Low-risk actions proceed on a local signature and sync later. High-risk actions use pre-provisioned, time-limited offline tokens with spending caps, or are queued until connectivity returns.
- If the face check fails or the camera is poor, fall back to PIN or password.
10. Monitoring, re-enrollment, experimentation
- Drift monitoring: track privacy-safe aggregates such as match-score distributions, quality-gate failure rate, liveness reject rate, PIN-fallback rate, and latency by device tier. A falling genuine-score mean signals aging or camera drift.
- Re-enrollment: use silent template refresh after high-confidence, PIN-verified successes, and prompt full re-enrollment when scores degrade or after a long gap.
- Safe A/B testing: first run the new model in shadow mode (compute but do not act) and compare scores offline. Then ramp in stages (1%, 5%, 25%) with guardrails on false-reject rate, fallback rate, p95 latency, crash rate, fraud signals, and per-cohort gaps. Auto-rollback on breach. Note that FAR cannot be measured directly in production, so rely on offline red-team and attack suites.
Common mistakes
- Choosing 1:N identification for a logged-in user.
- Evaluating with random impostors only, or bootstrapping over pairs.
- Sending face images or embeddings to the server.
- Treating liveness as optional.
- Reporting a single overall accuracy with no cohort or device breakdown.
- Ignoring the camera and attestation attack surface, which is often easier than fooling the model.