Think like an attacker for ten minutes
A threat model asks four questions about your design: What are we building? What can go wrong? What are we doing about it? Did we do a good job? For an interview or a design review, a lightweight version is enough:
- Assets: what's valuable? Money, personal data, credentials, availability.
- Entry points: every arrow that crosses a trust boundary: public APIs, file uploads, webhooks, admin panels, third-party callbacks.
- Attackers: anonymous internet users, logged-in users acting maliciously, compromised partners, insiders.
- Threats for each entry point, using STRIDE as a prompt list:
| Letter | Threat | Example | Typical control |
|---|---|---|---|
| S | Spoofing identity | Stolen session token | Strong auth, MFA, short-lived tokens |
| T | Tampering | Changing the price in a checkout request | Server-side validation, signatures |
| R | Repudiation | "I never placed that order" | Audit logs, signed receipts |
| I | Information disclosure | Another user's invoice via a guessed ID | Object-level authorization, encryption |
| D | Denial of service | Flood of expensive search queries | Rate limits, WAF, caching, quotas |
| E | Elevation of privilege | Normal user calls an admin API | Least privilege, deny by default |
Threat modelling is walking around your house at night as a burglar would. You don't need to know every lock-picking technique; you notice the open window, the key under the mat and the ladder left by the wall. Most real breaches are open windows, not master locksmiths.
Trust boundaries in a picture
Encryption in transit
- TLS everywhere: user to edge, edge to origin, and service to service. "It's internal" isn't a reason to skip it; most breaches move laterally inside networks.
- mTLS between services, often handled automatically by a service mesh, gives both encryption and service identity (Authentication and Authorization).
- HSTS tells browsers to always use HTTPS; modern TLS versions only (1.2+, preferably 1.3).
- Certificates are issued and renewed automatically (ACME / managed certificates); expired certificates are a classic, embarrassing outage.
Encryption at rest and key management
Disks and managed databases are typically encrypted by default. The design questions are about keys: who can use them, how they're rotated, and how access is logged.
Envelope encryption is the standard pattern:
Why it's good:
- The master key never leaves the KMS (often backed by hardware security modules), and every use is logged.
- Large data is encrypted locally and fast; only the small data key travels to the KMS.
- Rotation means re-wrapping data keys under a new master key, not re-encrypting terabytes.
- Crypto-shredding: delete a tenant's key and their data becomes unreadable everywhere, including backups.
For especially sensitive fields (national ID numbers, bank accounts), add field-level encryption or tokenisation: replace the value with a random token, and keep the real value in a separate, tightly controlled vault. Card numbers are tokenised this way to keep most systems out of PCI-DSS scope.
Network boundaries
- Private subnets for services and databases; only load balancers face the internet.
- Security groups / firewall rules that allow only the specific ports and sources each component needs (deny by default).
- Egress control: services can reach only the external hosts they need, which limits data exfiltration and server-side request forgery.
- Admin access via SSO plus a VPN or identity-aware proxy, with just-in-time elevation and full session logging. No shared SSH keys.
- Segmentation: production separate from staging; payment systems in their own tightly controlled zone.