|$ curl https://forge-ai.dev/api/markdown?path=docs/system-design/security
$cat docs/security.md
updated Recently·30 min read·published

Security

System DesignAdvanced🎯Free Tools
Introduction

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

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.

threat-modeling.txt
TEXT
1STRIDE threat categories:
2
3S - Spoofing → impersonating a user or system
4T - Tampering → modifying data or code
5R - Repudiation → denying an action took place
6I - Information disclosure → leaking sensitive data
7D - Denial of service → exhausting resources
8E - Elevation of privilege → gaining unauthorized access
9
10Threat modeling process:
111. Decompose the system into components and data flows
122. Identify threats using STRIDE for each element
133. Rank threats by likelihood and impact
144. Design mitigations
155. Validate and iterate as the system changes

best practice

Threat modeling should happen early in design, not just before release. The cheapest time to fix a security flaw is when it is still a whiteboard diagram.
Defense in Depth

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.

defense-in-depth.txt
TEXT
1Defense-in-depth layers:
2
3Perimeter: CDN, WAF, DDoS protection
4Network: VPCs, subnets, security groups, NACLs
5Identity: Authentication, MFA, IAM
6Application: Input validation, parameterized queries, output encoding
7Data: Encryption at rest, encryption in transit
8Monitoring: Logging, alerting, anomaly detection
9Physical: Data center access controls
10
11An attacker must defeat several layers to reach sensitive data.

info

Avoid relying on a single perimeter. Internal services should also authenticate and authorize each other. The assumption that traffic inside the network is safe is the core flaw of the perimeter model.
Web Application Firewall

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.

ProtectionWhat It Blocks
SQL injectionMalicious SQL in request parameters
XSSScripts injected into user input
CSRFUnauthorized actions from authenticated sessions
Path traversalAttempts to access files outside intended directories
Bad botsAutomated scraping and credential stuffing

warning

A WAF can be bypassed by attackers who craft requests that evade signature rules. Always validate and sanitize input in the application as well. Treat the WAF as a safety net, not a primary control.
DDoS Mitigation

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.

ddos.txt
TEXT
1DDoS mitigation layers:
2
3Layer 3/4 (network): CDN and upstream provider absorb
4 volumetric attacks before they reach origin.
5
6Layer 7 (application): WAF and rate limiting block slowloris,
7 credential stuffing, and expensive queries.
8
9Origin 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

The most effective DDoS defense is absorbing traffic before it reaches your infrastructure. Use a CDN or DDoS protection service in front of your origin, and keep your origin IP addresses private.
Encryption

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 StateMechanismKey Consideration
In transitTLS 1.2+, mTLSCertificate rotation, cipher suites
At restAES-256, KMS-managed keysKey rotation, access logging
In useConfidential computing, enclavesEmerging, higher overhead

best practice

Manage keys separately from data. A KMS with strict IAM policies, audit logging, and automatic rotation is far safer than embedding keys in code or configuration files.
Identity and Access

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.

iam.txt
TEXT
1Least-privilege IAM example:
2
3Role: order-service
4 Allowed:
5 - orders:read
6 - orders:write
7 Denied:
8 - payments:*
9 - users:delete
10
11Role: payment-worker
12 Allowed:
13 - payments:process
14 - payments:refund
15 Denied:
16 - orders:write
17
18No service should have blanket admin access.

warning

Secrets such as API keys, database passwords, and signing certificates must never be committed to source control. Use a secrets manager or vault, inject secrets at runtime, and rotate them regularly.
Zero Trust Architecture

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 ModelZero Trust Model
Trust inside the networkNever trust, always verify
VPN for remote accessIdentity-aware proxy for every resource
Flat network segmentationMicro-segmentation and mTLS
Static credentialsShort-lived tokens, continuous validation
🔥

pro tip

Implement zero trust incrementally. Start with strong identity for humans, then add service-to-service mTLS, then move to fine-grained authorization and continuous device posture checks.
Security Checklist

A checklist cannot replace threat modeling, but it helps catch common oversights. Review this list before shipping any system design.

All external traffic uses TLS 1.2 or higher
Secrets are stored in a secrets manager, not code
Input is validated and parameterized queries prevent injection
Services authenticate and authorize each other
Rate limiting and WAF rules are configured
Logs do not contain secrets or excessive personal data
Backups are encrypted and tested regularly
📝

note

Security is a process, not a product. Schedule regular reviews, penetration tests, and incident response drills. The strongest architecture will degrade if the team does not maintain it.
Secure Development Lifecycle

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.

sdlc.txt
TEXT
1Secure SDLC stages:
2
3Design: Threat model and define trust boundaries
4Develop: Use approved libraries, avoid dangerous APIs
5Build: SAST/DAST scans, dependency vulnerability checks
6Deploy: Immutable artifacts, signed containers, IaC scanning
7Operate: Log, monitor, patch, rotate secrets
8Respond: Runbooks, forensics, post-mortems, feedback loop
PracticeToolingValue
SASTSonarQube, Semgrep, CodeQLCatch injection, unsafe patterns
DASTOWASP ZAP, Burp SuiteFind runtime vulnerabilities
SCASnyk, Dependabot, FOSSAFlag vulnerable dependencies
Secrets scanninggit-secrets, TruffleHogPrevent credential leaks

best practice

Block merges that introduce high-severity vulnerabilities or leaked secrets. Security gates in CI/CD are far cheaper than incident response after a breach.
$Blueprint — Engineering Documentation·Section ID: SD-SEC-01·Revision: 1.0