Security basics for system design

Topic 5 of 8 in Week 6: Production concerns10 min readIntermediateFree course

Overview

Security isn’t a component you add at the end; it’s a property of every layer. In design interviews you’re rarely asked to design a security system, but a design that exposes private files or trusts every internal call raises flags. This lesson covers the essentials you should mention and get right.

Defence in depth

Defence in depth with four layers. Edge: TLS everywhere, DDoS protection, a web application firewall and bot filtering. API gateway: authentication with OAuth 2 or OpenID Connect and JWTs, rate limits and input size limits. Services: authorisation on every request, input validation and mutual TLS between services. Data: encryption at rest, least-privilege access, secrets in a vault and audit logs. Authentication is who you are; authorisation is what you may do, so check ownership on every object. Assume any one layer can fail: monitor, log access, rotate keys and patch dependencies.

No single control is perfect, so layer them. If the WAF misses an attack, input validation catches it; if a service is compromised, least-privilege credentials limit what it can reach; if data is stolen, encryption limits its value.

Encryption

  • In transit: TLS for every connection, including between internal services and to databases. A service mesh can provide mutual TLS (mTLS), where both sides present certificates, giving encryption and service identity.
  • At rest: encrypt disks, databases, backups and object storage (usually a checkbox with managed services), with keys in a key management service (KMS). For especially sensitive fields, add application-level encryption or tokenisation (payment card data is typically handled by a PCI-compliant provider so you never store it).

Authentication

Proving who a user or service is:

  • Users sign in through an identity provider using OAuth 2.0 and OpenID Connect, with MFA for sensitive accounts. Don’t build password storage yourself if you can avoid it; if you must, hash with a slow algorithm such as bcrypt, scrypt or Argon2.
  • After sign-in, clients carry a token: a short-lived access token (often a signed JWT) plus a refresh token, or a session ID in a secure, HTTP-only cookie (week 1, stateless services).
  • Services authenticate to each other with mTLS certificates or signed service tokens, not shared passwords.
  • The gateway can validate tokens once and pass a trusted identity downstream.

Authorisation

Deciding what an authenticated identity may do. This is where many real breaches happen:

  • Check on every request and every object. GET /files/981 must verify that the caller can access file 981, not just that they’re logged in. Missing object-level checks (IDOR) are among the most common API vulnerabilities.
  • Use clear models: role-based (admin, editor, viewer) or attribute/relationship-based (owner, shared-with, same organisation).
  • Enforce in the service that owns the data, close to the data.

Least privilege and secrets

  • Each service gets its own credentials with only the permissions it needs (its own database user, a scoped cloud role).
  • Keep secrets (API keys, database passwords) in a secrets manager (Vault, AWS Secrets Manager), never in code or Git, and rotate them.
  • Limit and audit human access to production.

Input and output

  • Validate input (types, sizes, formats) at the boundary and again where it matters.
  • Use parameterised queries to prevent SQL injection; escape output to prevent cross-site scripting.
  • Limit request and upload sizes; scan uploaded files; never trust file names or content types from clients.
  • Protect against server-side request forgery when your server fetches user-supplied URLs.

Abuse and availability

  • DDoS protection and a WAF at the edge (CDN providers offer both).
  • Rate limiting per user, key and IP; stricter limits on login and sign-up.
  • Bot detection and CAPTCHAs for sign-up, login and checkout abuse.

Privacy and audit

Collect only the personal data you need, know where it lives, support deletion requests, and respect data-residency rules (GDPR, India’s DPDP Act and similar laws). Keep audit logs of sensitive actions (who accessed what, when) in tamper-resistant storage.

In an interview

A short, specific sentence goes a long way: “All traffic is TLS, with mTLS inside; the gateway validates OAuth tokens; services check object ownership on every request; files live in a private bucket served via presigned URLs; secrets are in a vault; login is rate-limited.”

Recap

Secure designs layer defences at the edge, gateway, services and data. Encrypt in transit and at rest, authenticate users with standard protocols and short-lived tokens, authorise every request against the specific object, give every component least privilege with secrets in a vault, validate input, and protect against abuse with rate limits, WAF and DDoS protection.

Exercise

Secure a file-sharing API

Review this design for a file-sharing app and list the security fixes: (1) the mobile app calls GET /files/{fileId} with a JWT; the server checks the JWT signature and returns the file; (2) files are stored in a public S3 bucket so downloads are fast; (3) the database password is in the service's config file in the Git repository; (4) internal services call each other over plain HTTP inside the VPC; (5) there's no limit on login attempts.

Text
(1)
(2)
(3)
(4)
(5)

Summary

  • Defence in depth: layer protections at the edge, gateway, services and data so one failure isn't a breach.
  • Encrypt in transit (TLS everywhere, including inside the network) and at rest; manage keys and secrets in a vault.
  • Authentication proves identity (OAuth 2.0 / OpenID Connect, tokens, MFA); authorisation checks what that identity may do on every request and object.
  • Validate input, use parameterised queries, and apply least privilege to every service and person.
  • Protect against abuse with rate limits, WAF and DDoS protection, and keep audit logs.