esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Security: Only the Right Callers Reach the Right Data, and Breaches Stay Small

Learn how to design a system so only the right people and services reach the right data, using the CIA triad, least privilege, trust boundaries, and a checkout example.

In short

System security is designing so only the right people and services reach the right data and any breach stays small, guided by the CIA triad and least privilege.

14 min readFree

What You Will Learn

Security is the work of making sure that only the right people and services can reach the right data and actions. In this course, security is a design concern from the start. You decide who may call what, where data lives, and which parts trust each other while you draw the system, not after it is built. This lesson covers three security goals, two principles that shape most designs, the difference between proving who someone is and deciding what they may do, how data is protected, and a simple method for finding weak spots early.

Read the key words first. Each one is used later in the lesson.

Key words

Asset
Anything of value that a system holds or does, such as customer records, payment tokens, or the ability to place an order.
Attacker
Anyone or anything that tries to misuse a system, such as a bot, a curious customer, or a former employee with leftover access.
Entry point
A place where input from outside can reach the system, such as a web page, a login form, or an API (a door that other programs use to ask your system for things).
Trust boundary
A line in a design where the level of trust changes, such as where data from the internet enters your servers.
CIA triad
A model with three security goals: confidentiality (secrecy), integrity (accuracy), and availability (being ready to use).
Least privilege
Giving each user, service, or program only the permissions it needs for its job, and no more.
Defense in depth
Stacking several separate layers of protection so that one failed layer does not open the whole system.
Authentication
Proving who a caller is, usually with a password, a code, a certificate, or a secret key.
Authorization
Deciding what an already identified caller is allowed to see or do.
TLS
Transport Layer Security, the standard way to encrypt data as it travels between a client and a server, so people on the path cannot read or change it.
Secret
A value that must stay private, such as a password, an API key, or a database login.
Control
A safeguard placed in a design to lower a risk, such as a check, a limit, a boundary, or a log.

Why Does Security Start at the Design?

A common mistake is to build a product first and then add protection at the end. That approach leaves gaps, because the most important decisions were already made. Which service may call which other service, where sensitive data is kept, and which parts face the internet are all design decisions. Early fixes are cheap. Late fixes often mean rebuilding parts that already run in production.

Security is therefore a property of the shape of the system, not only of the lines of code. A strong login form cannot save a design where every service can read every table.

Tip

When you sketch a new feature, write down who should be able to use it before you write down how it works. If you cannot name the allowed users, you are not ready to design the protection yet.

What Is the CIA Triad?

The CIA triad is the most common starting point for security goals. It names three things that can go wrong with information, and each one needs its own protection.

  • Confidentiality

    Secrecy. Only authorized people and systems should be able to read sensitive data. A leaked customer database is a confidentiality failure.

  • Integrity

    Accuracy. Data should stay correct and change only through approved paths. A forged payment instruction or a silently edited price is an integrity failure.

  • Availability

    Readiness. Authorized users should be able to reach the system when they need it. A ransomware lockout (a malware attack that locks your files until you pay) or a dead data center is an availability failure.

The three goals often pull against each other. Strict access rules and encryption protect secrecy, but they can also lock out a legitimate user. Extra copies of data keep a service up, but every copy is one more place where data could leak. Good design chooses this balance on purpose and writes the choice down.

Use the triad as a review habit. For each asset, ask what happens if secrecy fails, what happens if accuracy fails, and what happens if access fails. Your answers show which controls to place first.

Tip

If the honest answer to all three questions is 'nothing much,' ask whether that asset really needs to be in the system at all.

What Two Principles Shape Every Design?

Least privilege means that each user, service, or program gets only the permissions it needs to do its job. If one part is compromised, the damage it can do is limited to what that part was allowed to touch.

Defense in depth means that protection comes in several separate layers. An attacker who gets past one layer should still meet the next one. No single check is trusted to stop everything.

  • Least privilege in architecture

    Give each service its own database account, and let that account read or write only its own tables. A product page service that only shows items should never hold a key that changes prices.

  • Defense in depth in architecture

    Stack a network rule, a login check, an ownership check, and a narrow database permission. A request must pass each one, so a single bug does not expose the whole store.

Tip

If one stolen password would let an attacker reach every service, the design is missing least privilege and defense in depth at the same time.

Who Are You, and What May You Do?

Security needs two different decisions, and they should never be merged into one. The first is about identity. The second is about permission. The two are often confused, and that confusion causes real bugs.

  • Authentication

    Checks identity. It answers the question of who is calling. A password plus a one-time code is a common example.

  • Authorization

    Checks permission. It answers the question of what this identified caller may see or change. A customer may read their own order, but not someone else's.

Authentication comes first, because you cannot decide what someone may do until you know who they are. But a successful login does not finish the job. Every later request still needs an authorization check. Many real breaches happen here: the system checks that a user is logged in, then forgets to check that the user owns the record requested.

Key words

Session
A short record the server keeps after login, so it knows the next request comes from the same signed-in caller.
One-time code
A code that works once and expires quickly, often sent to a phone or made by an app, used as a second proof of identity.

Tip

When you review a feature, ask two questions separately: how does the system know who this is, and where does it check that this person may do this exact action on this exact item?

How Do You Protect Data on the Wire and on Disk?

Data can be read or changed in two main states. In transit, it moves between a browser and a server, or between two services. At rest, it sits in a database, a file, or a backup. Each state needs its own protection. Encryption is the scrambling of data so that only a holder of the right key can read it. If the keys are lost, the data is effectively lost too.

What Is Encryption in Transit with TLS?

TLS wraps a network connection so that people on the path cannot read or alter what passes through it. A web address that starts with https uses TLS. A sound design uses TLS between the browser and the server, and also between internal services that carry sensitive data.

Encryption at Rest

Encryption at rest protects stored data. If a disk or a backup is stolen, the copy stays unreadable without the key. The key must then be kept somewhere safer than the data it protects, otherwise the lock and the key sit together.

Keeping Secrets Out of Code

A secret is any value that proves identity or unlocks access, such as a database password, an API key, or a signing key (a key used to prove that a message is genuine). Secrets must never be written into source code. Code is copied to laptops, build servers, and shared repositories, so a secret in a shared repository should be treated as leaked. Keep secrets in a dedicated secret store, load them when the program runs, and rotate them, meaning replace them on a schedule or right after any suspected leak.

Tip

If you find a secret in code, replace the secret first. Deleting the line is not enough, because the old value stays in the repository's history.

Threat Modeling: Find Weak Spots Early

Threat modeling is a structured way to find what can go wrong before a system is built. It needs no expensive tools. A sheet of paper and an honest diagram are enough. Work through these steps for any new design.

  1. 1

    Identify the assets

    List what is worth protecting, such as customer records, payment tokens, order history, and admin rights. Write down why each one matters.

  2. 2

    Map the entry points

    Draw every place where outside input can reach the system. Web pages, login forms, public APIs, and admin consoles are common examples.

  3. 3

    Name the attackers

    Think about who would misuse each asset. Consider a bot scanning for weak logins, a customer reading another customer's data, and a former employee who still has access.

  4. 4

    Mark the trust boundaries

    Draw a line wherever the level of trust changes, such as the internet to your servers, or your system to a third-party payment provider.

  5. 5

    Place the controls

    Put a safeguard at each boundary crossing. Input validation, rate limits, network boundaries, and audit logs are typical controls for these crossings.

A popular checklist for the threat step is STRIDE. It names six kinds of threat. Spoofing is pretending to be someone else. Tampering is changing data without permission. Repudiation is denying an action that no record can prove. Information disclosure is leaking data. Denial of service is making a system unavailable. Elevation of privilege is gaining rights you should not have. Ask which of the six apply to each type of element in your diagram, since each element type faces only some of them.

Key words

Input validation
Checking that incoming data has the expected type, size, and shape before the system uses it.
Rate limit
A cap on how many requests one caller may send in a set time window.
Audit log
A record of who did what and when, kept so that investigators can later see what happened.

Placing Controls at Trust Boundaries

A trust boundary is the most useful line you can draw. Each time data crosses from a low-trust zone into a higher-trust zone, it deserves a check. Input from a phone app is a good example. The phone is outside your control, so the API that receives its data must validate that data again, even if the app already did. Network boundaries keep the database reachable only from the application servers. Audit logs let you investigate a suspicious order later.

Tip

Most threats gather at the boundaries. Draw the boundaries first, then ask the six STRIDE questions mainly at those lines.

Worked Example: An Online Store Checkout

This is a teaching sketch of a generic online store checkout. It is not a description of how any real store builds its checkout. Follow one shopper from sign-in to payment.

  1. 1

    Sign in (authentication)

    The shopper enters a password and a one-time code. The system checks both and creates a session. The store keeps only a scrambled form of the password, never the readable password.

  2. 2

    Open the order list (authorization)

    When the shopper opens 'my orders', the order service checks each order's owner against the signed-in shopper before returning anything. The check runs on every request, even when the shopper types an order number into the address bar.

  3. 3

    Send card details over TLS

    The card form travels over TLS. In a common design, the card number goes to a payment provider, which returns a token. The store keeps the token, not the full card number, so a breach of its database exposes less.

  4. 4

    Validate at the trust boundary

    The browser is outside the trusted zone. The order service checks the quantity, the address format, and the coupon code before using them. It also looks up the price on the server, so a price sent by the browser is ignored.

  5. 5

    Limit and log

    A rate limit slows bots that try many card numbers in a short time. Each payment attempt and each order view is written to an audit log.

  6. 6

    Keep database permissions narrow

    The checkout service's database account can write new orders and read the cart. It cannot read the full customer table or change the product catalog.

The checks layer on top of each other. Login stops strangers. The ownership check stops a signed-in shopper from reading someone else's order. The token keeps card numbers away from the store's own servers. Each control protects at least one of the CIA goals.

The ownership idea fits in a few lines. This function answers one question: may this signed-in user view this order?

Python
def can_view_order(signed_in_user, order_owner):
    return signed_in_user == order_owner

print(can_view_order('alice', 'alice'))
print(can_view_order('alice', 'bob'))

Output

True
False

Real systems check more than the owner, such as roles and order status. The principle stays the same: the check runs on the server, on every request, before any data is returned.

Check Your Understanding

Try each scenario before you read the explanation. Each one needs one of the ideas from this lesson.

Quick check

A team stores a database password in a public code repository. Every internal service uses the same admin account to read the database. Which two principles are broken, and what should change first?

Quick check

A shopper signs in to your store, then changes the order number in the address bar and sees a stranger's order. Which control is missing?

Quick check

A phone app sends an order form to your API. The app already checks that the quantity is a positive whole number. Where should your team check it again?

Key Takeaways

  • Design it in

    Decide who may reach each asset while you draw the system, not after launch.

  • Keep the goals in view

    Ask what happens to each asset if secrecy, accuracy, or access fails.

  • Separate identity from permission

    Prove who the caller is, then check what that caller may do on every request.

  • Guard the boundaries

    Validate, limit, separate, and log at each place where trust changes.

Security is not one feature. It is the sum of many small decisions that limit who can reach what, and keep a breach in one place from spreading. Start with the assets and the boundaries, and the right controls become much easier to choose.

Sources

How is this lesson?

Last updated on 18 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.