Skip to main content

Module 7: Security

Security Fundamentals

DDoS protection, WAF, TLS, encryption at rest, authn/authz, secrets, and least privilege — security basics for system design interviews.

Security is a layer in the diagram, not a footnote. Interviewers want practical controls matched to threats — abuse, injection, data leak, and downtime — not vague “military-grade” claims.

What you will learn

  • Threat-model lightly and place controls on the request path
  • Place DDoS/WAF/TLS protections at the edge
  • Contrast encryption in transit vs at rest and key management
  • Separate authentication from authorization with least privilege
  • Handle secrets, logging redaction, and baseline secure defaults
Four layers: edge TLS and WAF, gateway auth, service checks, and an encrypted database.
Stop abuse at the edge. Check identity at the gateway. Encrypt the data and limit who can read it.

Threat model first

  • Name what you are defending against before listing tools. Specific beats buzzwords.
  • Abuse / bots — credential stuffing, scraping, spam
  • Application attacks — injection, XSS, SSRF, path traversal
  • Availability — DDoS and resource exhaustion
  • Data leak — stolen disks, backups, logs, misconfigured buckets
  • Insider / lateral movement — overly broad credentials inside the VPC

Where security sits on the path

  • Walk Client → edge → gateway → services → data and attach controls at each hop.
  • Edge: DDoS scrubbing, CDN, WAF, TLS termination
  • Gateway/API: authn, rate limits, input size/schema checks
  • Services: authz, parameterized queries, SSRF egress controls
  • Data: encryption at rest, least-privilege DB roles, private subnets
  • Ops: secrets manager, audit logs, patching, backups

DDoS & availability

  • Availability is a security property. Overwhelm is a common attack.
  • Absorb volumetric attacks with anycast CDN / scrubbing providers
  • Rate limit and bot challenges at edge/gateway
  • Autoscale carefully — scaling alone can amplify cost under attack
  • Synthesize health: fail closed on auth, fail soft on noncritical features
  • Separate public edge from origin; keep origins private

WAF & application edge

  • A Web Application Firewall inspects HTTP before it hits your app.
  • Managed rules for common SQLi/XSS/path attacks
  • Geo/IP allow-deny, bot scores, virtual patches
  • Not a substitute for secure application code
  • Tune false positives — blocking real users is also an outage
  • Combine with gateway validation for defense in depth

Encryption in transit

  • Protect data while it moves. Interviewers expect TLS as a default.
  • TLS on all public endpoints; prefer modern protocols/ciphers
  • Terminate at CDN/LB; consider re-encrypt to apps (TLS everywhere)
  • Service-to-service mTLS inside the mesh for stronger identity
  • Certificate management and rotation are part of the design
  • Never send tokens/passwords over plain HTTP

Encryption at rest & keys

  • Disks get stolen, snapshots leak, backups spread. Encrypt stored data.
  • Volume/disk encryption for databases, disks, and object storage
  • Field-level encryption for highly sensitive fields (PAN, secrets)
  • Keys in KMS/HSM — apps get decrypt permissions, not raw master keys
  • Encrypt backups and verify restore still works
  • HTTPS does not encrypt data sitting on disk

Authentication vs authorization

  • Authn answers who you are; authz answers what you may do. Keep them distinct.
  • Authn: passwords+MFA, OAuth/OIDC, session cookies, API keys, mTLS
  • Authz: RBAC/ABAC checks in the service that owns the resource
  • Gateway can validate JWTs; services still enforce object-level permissions
  • Short-lived tokens; refresh carefully; revoke on logout/compromise
  • Service accounts get least privilege — no “admin for convenience”

Secrets, config, and supply chain

  • A leaked .env file undoes elegant architecture diagrams.
  • Secrets manager / vault — never commit secrets to git
  • Rotate credentials; prefer IAM roles over long-lived keys
  • Inject secrets at runtime; scope by environment
  • Pin/verify dependencies; scan images and containers
  • Separate prod credentials from staging completely

App & data hygiene

  • Most breaches still exploit boring basics.
  • Parameterized queries / ORM bindings — no string-built SQL
  • Validate and encode output to reduce XSS
  • CSRF protections for cookie-based browser sessions
  • Private subnets for DB; security groups as allowlists
  • Redact PII from logs; centralize audit trails for admin actions

Common interview mistakes

  • Avoid theater. Be concrete.
  • Saying “we’ll add security later” with no boxes on the diagram
  • Claiming HTTPS alone protects stored data
  • Putting the database on a public IP
  • One shared superuser credential for all services
  • Logging access tokens or card numbers

Interview framing

  • Use this checklist when any design touches users or sensitive data.
  • Name top threats for this product in one breath
  • Draw edge: TLS + WAF/DDoS + rate limit
  • Show authn at gateway and authz in services
  • Mark encryption at rest + KMS for the data stores
  • Call out secrets handling and private networking

Quick revision checklist

  • Threat model lightly: abuse, injection, data leak, downtime.
  • Don’t claim “military-grade” — be specific.
  • TLS in transit and encryption at rest are both required.
  • Authn ≠ authz — say both.
  • Least privilege IAM and secret rotation.
  • Keep databases private; expose only the edge.

FAQs

Does HTTPS replace encryption at rest?

No. HTTPS protects data moving on the wire. Disks, snapshots, and backups need at-rest controls too.

Where should a WAF sit?

Usually at the CDN or reverse-proxy edge, inspecting HTTP before traffic reaches application servers.

Is rate limiting security?

It is part of availability and abuse defense. Place coarse limits at the edge/gateway; finer limits may live in services. Details are in the Rate Limiting lesson.

JWT validation at the gateway — enough?

It authenticates the caller. Services must still authorize actions on specific resources (object-level checks).

Where do we store API keys and DB passwords?

In a secrets manager/KMS-backed vault, injected at runtime with least privilege — never in source control or world-readable config files.

What is mTLS?

Mutual TLS: both client and server present certificates. Common for service-to-service identity inside a private network or mesh.

Practice

Learner’s Task

  • Practice out loud for 8–10 minutes. Add a security layer to any system you already designed.
  1. Pick a product (URL shortener or chat) and list four realistic threats.
  2. Redraw the edge with TLS, WAF/DDoS, and rate limiting — say what each stops.
  3. Mark authn vs authz: where tokens are validated and where object permissions are checked.
  4. State at-rest encryption + KMS for the primary data store and how secrets are loaded.
  5. Write a 4-sentence closing: threats, edge controls, identity model, and data protection.