No history yet

Security in System Design

Who Goes There?

In a distributed system, countless services and users are constantly interacting. Before any service responds to a request, it must answer two fundamental questions: Who are you? And what are you allowed to do?

These questions are the core of authentication and authorization.

Authentication

noun

The process of verifying the identity of a user, service, or device. It's like showing your ID to prove you are who you claim to be.

Authentication confirms an identity, but it doesn't say anything about permissions. That's where authorization comes in.

Authorization

noun

The process of determining if an authenticated user, service, or device has permission to access a specific resource or perform an action.

Think of it this way: Authentication is showing your driver's license to a bouncer. Authorization is the bouncer checking your age on the license to see if you can enter the club.

In modern distributed systems, especially those using microservices, these checks are often handled by a centralized service or an API Gateway. When a request comes in, the gateway authenticates the user, often using standards like OAuth 2.0, and attaches a token to the request. Downstream services can then inspect this token to authorize the request without needing to know the user's password. This approach avoids scattering security logic across every single service.

Keeping Secrets Safe

Once a user is authenticated and authorized, the system still has a duty to protect their data. Security isn't just about controlling access at the front door; it's about protecting information everywhere, whether it's sitting in a database or flying across the network. This involves encryption.

Data in Transit refers to data moving from one point to another, like from a user's browser to your server, or between two of your microservices. This data must be encrypted to prevent eavesdroppers from intercepting it.

Data at Rest is data that is not actively moving, such as information stored in a database, a log file, or a file system. Encrypting this data protects it even if an attacker gains physical access to the storage hardware.

When designing your system, consider the places where encryption will be needed.

For data in transit, the standard protocol is Transport Layer Security (TLS), the successor to Secure Sockets Layer (SSL). When you see https:// in your browser's address bar, you're using TLS. It creates a secure, encrypted channel between a client and a server, ensuring that any data passed between them remains private and integral. This is essential not just for user-facing applications but also for communication between internal services in a distributed architecture.

Lesson image

Encrypting data at rest is just as important. If a server or hard drive is stolen, unencrypted sensitive data like user information or financial records would be completely exposed. Most modern database systems and cloud storage providers offer transparent data encryption, which automatically encrypts data before it's written to disk and decrypts it when it's read by an authorized process.

Common Weak Spots

Even with strong authentication and encryption, vulnerabilities can still exist. Distributed systems introduce unique challenges because of their many moving parts and network dependencies. Here are a few common pitfalls and how to address them.

VulnerabilityDescriptionMitigation Strategy
Insecure Service-to-Service CommunicationServices within a trusted network often communicate without encryption, assuming the network is safe.Implement mutual TLS (mTLS), where services must authenticate each other before communicating. Use API gateways to enforce security policies.
Credential and Secret MismanagementHardcoding passwords, API keys, or other secrets in code or configuration files.Use a dedicated secret management tool (like HashiCorp Vault or AWS Secrets Manager) to store and dynamically inject secrets at runtime. Rotate credentials regularly.
Inadequate Logging and MonitoringNot having enough visibility into what's happening across all services, making it hard to detect an attack.Implement centralized logging and monitoring. Set up alerts for suspicious activities, like failed login spikes or unusual API requests.
Denial of Service (DoS) AttacksAn attacker overwhelms a service with traffic, making it unavailable to legitimate users.Use rate limiting to control how many requests a user or IP address can make in a given time. Use a load balancer to distribute traffic and absorb spikes.

Thinking about security from the very beginning of the design process is the best way to build a resilient system. It's not an add-on; it's a fundamental part of the architecture.

Time to check your understanding of these security principles.

Quiz Questions 1/5

What is the primary function of authorization in a distributed system?

Quiz Questions 2/5

Encrypting data stored in a database is crucial because it protects the information even if an attacker gains physical access to the storage hardware.

Building secure systems requires a layered approach, from verifying identity at the entry points to encrypting data and monitoring for threats. By integrating these practices into your design, you can protect your system and its users from harm.