Security at Scale
Security as a system-design concern — threat modelling (STRIDE), defence in depth, zero trust and service identity, encryption in transit and at rest with envelope encryption and KMS, secrets management, DDoS protection, bot and abuse prevention, fraud signals, multi-tenancy isolation, data privacy (PII, GDPR deletion, data residency), audit logging and supply-chain security.
Defence in depth
Threat modelling with STRIDE
| Threat | Property violated | Typical mitigations |
|---|---|---|
| Spoofing | authentication | MFA, mTLS, signed tokens, passkeys |
| Tampering | integrity | TLS, HMAC/signatures, checksums, immutable logs |
| Repudiation | non-repudiation | tamper-evident audit logs, signed requests |
| Information disclosure | confidentiality | encryption, authorization, data minimisation |
| Denial of service | availability | rate limiting, autoscaling, CDN, quotas |
| Elevation of privilege | authorization | least privilege, sandboxing, patching |
Encryption
| Where | How |
|---|---|
| In transit (external) | TLS 1.3, HSTS, modern ciphers, certificate automation |
| In transit (internal) | mTLS via mesh |
| At rest | disk/volume encryption + application-level envelope encryption for sensitive fields |
| In use | confidential computing (enclaves) for the highly sensitive |
| Passwords | Argon2id/bcrypt — hashing, not encryption |
| Tokenisation | replace card numbers/PII with tokens; vault holds the mapping (shrinks PCI scope) |
Secrets management
Never in code, images or plain env files in repos. Use a secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager) with fine-grained access policies and audit logs; prefer dynamic, short-lived credentials (Vault DB secrets engine, IAM roles via workload identity) over static keys; rotate automatically; scan repos and images for leaked secrets (pre-commit hooks, GitHub secret scanning).
Abuse, bots and fraud
| Abuse | Controls |
|---|---|
| Credential stuffing / account takeover | rate limits per account and IP, breached-password checks, MFA/passkeys, risk-based auth (new device/location → step-up) |
| Scraping | rate limits, bot detection, behavioural fingerprinting, honeypot fields, legal/ToS |
| Spam / fake accounts | phone/email verification, reputation scores, ML classifiers, friction for new accounts |
| Payment fraud | risk scoring (velocity, device, geography, card BIN), 3-D Secure, manual review queues |
| Promo / referral abuse | device fingerprint, idempotency and per-user limits, graph analysis of linked accounts |
Architecture: an async risk/abuse pipeline consumes events (logins, signups, payments), computes features in streaming (counts per IP/device over windows), scores with rules + ML, and feeds decisions back (block, challenge, review) via a low-latency decision API at the edge.
Multi-tenancy isolation
-- PostgreSQL row-level security: the database itself enforces tenant isolation
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
USING (tenant_id = current_setting('app.tenant_id')::uuid);
-- per request, in the same transaction/connection:
SET LOCAL app.tenant_id = '6f1c…'; -- derived from the verified token, never from input
SELECT * FROM invoices; -- only this tenant's rows
Privacy and compliance
| Topic | Design implication |
|---|---|
| Data minimisation | collect only what's needed; TTLs on raw data |
| PII classification | tag fields; restrict access; mask in logs and non-prod |
| Right to erasure (GDPR) | data inventory + deletion events + crypto-shredding |
| Data residency | region-pinned storage and processing (cells per region) |
| PCI DSS | tokenise cards via a PSP; keep card data out of your systems |
| HIPAA / SOC 2 | access controls, audit logs, encryption, vendor agreements |
| Audit logging | append-only, tamper-evident (hash-chained or WORM storage), who did what when |
Supply chain security
Pin and verify dependencies (lockfiles, checksums), scan for vulnerabilities (SCA), generate SBOMs, sign build artifacts and images (Sigstore/cosign), enforce provenance (SLSA levels), build in isolated ephemeral CI runners with least-privilege tokens, and admit only signed images into clusters (admission policies).
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.