Security
Security in system design is the practice of protecting systems, data, and users from threats. It is not a feature added at the end; it is an emergent property of architecture, code, processes, and culture. A secure system assumes breach and limits damage through defense in depth.
This guide covers the security layers that matter in distributed systems: threat modeling, network controls, web application firewalls, DDoS mitigation, encryption, identity, and zero trust. The goal is not to make you a security specialist, but to ensure you can design systems that are resilient by default.
Security and usability are often in tension. The best security designs make the right thing easy and the wrong thing hard, without adding friction that drives users to work around controls.
Threat modeling is a structured way to identify, quantify, and address security risks. The STRIDE model is a common framework: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service, and Elevation of privilege.
| 1 | STRIDE threat categories: |
| 2 | |
| 3 | S - Spoofing → impersonating a user or system |
| 4 | T - Tampering → modifying data or code |
| 5 | R - Repudiation → denying an action took place |
| 6 | I - Information disclosure → leaking sensitive data |
| 7 | D - Denial of service → exhausting resources |
| 8 | E - Elevation of privilege → gaining unauthorized access |
| 9 | |
| 10 | Threat modeling process: |
| 11 | 1. Decompose the system into components and data flows |
| 12 | 2. Identify threats using STRIDE for each element |
| 13 | 3. Rank threats by likelihood and impact |
| 14 | 4. Design mitigations |
| 15 | 5. Validate and iterate as the system changes |
best practice
Defense in depth means layering security controls so that a single failure does not lead to compromise. If one layer is bypassed, the next layer provides protection. No single control is perfect; together they raise the cost of attack.
| 1 | Defense-in-depth layers: |
| 2 | |
| 3 | Perimeter: CDN, WAF, DDoS protection |
| 4 | Network: VPCs, subnets, security groups, NACLs |
| 5 | Identity: Authentication, MFA, IAM |
| 6 | Application: Input validation, parameterized queries, output encoding |
| 7 | Data: Encryption at rest, encryption in transit |
| 8 | Monitoring: Logging, alerting, anomaly detection |
| 9 | Physical: Data center access controls |
| 10 | |
| 11 | An attacker must defeat several layers to reach sensitive data. |
info
A Web Application Firewall (WAF) inspects HTTP traffic and blocks malicious requests. It protects against common attacks such as SQL injection, cross-site scripting (XSS), and cross-site request forgery (CSRF). A WAF is a valuable layer but not a substitute for secure application code.
| Protection | What It Blocks |
|---|---|
| SQL injection | Malicious SQL in request parameters |
| XSS | Scripts injected into user input |
| CSRF | Unauthorized actions from authenticated sessions |
| Path traversal | Attempts to access files outside intended directories |
| Bad bots | Automated scraping and credential stuffing |
warning
Distributed Denial of Service (DDoS) attacks overwhelm a system with traffic, making it unavailable to legitimate users. Mitigation happens at multiple layers: DNS, network, transport, and application. Cloud providers and CDNs offer scrubbing services that absorb and filter attack traffic.
| 1 | DDoS mitigation layers: |
| 2 | |
| 3 | Layer 3/4 (network): CDN and upstream provider absorb |
| 4 | volumetric attacks before they reach origin. |
| 5 | |
| 6 | Layer 7 (application): WAF and rate limiting block slowloris, |
| 7 | credential stuffing, and expensive queries. |
| 8 | |
| 9 | Origin hardening: |
| 10 | - Rate limiting per IP and per user |
| 11 | - Challenge suspicious traffic with CAPTCHA |
| 12 | - Auto-scale to absorb spikes |
| 13 | - Blackhole routes for attack sources |
| 14 | - Geo-blocking if traffic is geographically unexpected |
info
Encryption protects data from unauthorized access. Data in transit should use TLS 1.2 or higher. Data at rest should be encrypted using strong algorithms and key management. Encryption ensures that even if an attacker gains access to storage or network traffic, they cannot read the data without the keys.
Encryption in Transit
Use TLS for all public and internal service communication. Terminate TLS at the load balancer or gateway, and use mTLS between services for mutual authentication. Disable weak ciphers and enforce HSTS for browser clients.
Encryption at Rest
Encrypt databases, object storage, backups, and logs at rest. Use managed keys from a KMS where possible, and rotate keys periodically. For highly sensitive data, consider application-level encryption so that the database layer never sees plaintext.
| Data State | Mechanism | Key Consideration |
|---|---|---|
| In transit | TLS 1.2+, mTLS | Certificate rotation, cipher suites |
| At rest | AES-256, KMS-managed keys | Key rotation, access logging |
| In use | Confidential computing, enclaves | Emerging, higher overhead |
best practice
Identity and access management (IAM) controls who can do what. Authentication verifies identity. Authorization determines what actions an identity can perform. Both should be explicit, auditable, and based on least privilege.
| 1 | Least-privilege IAM example: |
| 2 | |
| 3 | Role: order-service |
| 4 | Allowed: |
| 5 | - orders:read |
| 6 | - orders:write |
| 7 | Denied: |
| 8 | - payments:* |
| 9 | - users:delete |
| 10 | |
| 11 | Role: payment-worker |
| 12 | Allowed: |
| 13 | - payments:process |
| 14 | - payments:refund |
| 15 | Denied: |
| 16 | - orders:write |
| 17 | |
| 18 | No service should have blanket admin access. |
warning
Zero trust assumes that no user, device, or service should be trusted by default, regardless of network location. Every access request is authenticated, authorized, and encrypted. This model replaces the traditional perimeter-based security model, which treats internal traffic as safe.
| Perimeter Model | Zero Trust Model |
|---|---|
| Trust inside the network | Never trust, always verify |
| VPN for remote access | Identity-aware proxy for every resource |
| Flat network segmentation | Micro-segmentation and mTLS |
| Static credentials | Short-lived tokens, continuous validation |
pro tip
A checklist cannot replace threat modeling, but it helps catch common oversights. Review this list before shipping any system design.
note
Security must be embedded into the software development lifecycle, not bolted on before release. A secure SDLC includes threat modeling, code review, automated scanning, and incident response planning.
| 1 | Secure SDLC stages: |
| 2 | |
| 3 | Design: Threat model and define trust boundaries |
| 4 | Develop: Use approved libraries, avoid dangerous APIs |
| 5 | Build: SAST/DAST scans, dependency vulnerability checks |
| 6 | Deploy: Immutable artifacts, signed containers, IaC scanning |
| 7 | Operate: Log, monitor, patch, rotate secrets |
| 8 | Respond: Runbooks, forensics, post-mortems, feedback loop |
| Practice | Tooling | Value |
|---|---|---|
| SAST | SonarQube, Semgrep, CodeQL | Catch injection, unsafe patterns |
| DAST | OWASP ZAP, Burp Suite | Find runtime vulnerabilities |
| SCA | Snyk, Dependabot, FOSSA | Flag vulnerable dependencies |
| Secrets scanning | git-secrets, TruffleHog | Prevent credential leaks |
best practice