System design concepts · Staying Up and Staying Safe

Security in System Design Interviews

Security in high-level design is about boundaries: who can reach what, with which proof, what an attacker gets when one layer falls, and how fast you'd notice.

What you'll be able to explain
  • Threat-model a design in ten minutes with a simple checklist
  • Protect data in transit and at rest, and explain envelope encryption
  • Lay out network boundaries, WAF and DDoS protection
  • Recognise the common web and API vulnerabilities and their design-level fixes
  • Handle secrets, supply chain, personal data and incident response

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:

  1. Assets: what's valuable? Money, personal data, credentials, availability.
  2. Entry points: every arrow that crosses a trust boundary: public APIs, file uploads, webhooks, admin panels, third-party callbacks.
  3. Attackers: anonymous internet users, logged-in users acting maliciously, compromised partners, insiders.
  4. 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
Analogy

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

PROBLEMInternet usersuntrustedNETWORKCDN + WAFDDoS absorptionNETWORKAPI gatewayauth, rate limitsSERVICEServicesprivate subnetDATABASEDatabasesno public accessOKKMS / secretsCACHEAdmin panelVPN / SSO onlyEXTERNALPartner webhookssignedmTLSverify signature
Trust boundaries: every arrow that crosses from a less-trusted zone into a more-trusted one needs authentication, validation and limits.

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:

ServiceKMSStorage1generate data key2plaintext key + encrypted key3encrypt file with plaintext key, then discard it4store ciphertext + encrypted key5to read: send the encrypted key to KMS, get the plaintext key, decrypt
Envelope encryption: data is encrypted with a data key; the data key is encrypted with a master key that never leaves the KMS.

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.