API & BACKEND ARCHITECTURE / SYSTEM CONCEPT BRIEF

Authorization

Authorization (AuthZ) answers 'what are you allowed to do?'.

IntermediatePhase 02 / Topic 6 of 20RequirementsTrade-offsFailure modes
01

Overview

Authorization (AuthZ) answers 'what are you allowed to do?'. After a user or service is authenticated, every request must be checked against policy: can this user read this document, refund this order, or delete this project? Authorization failures are the most common serious API vulnerability.

Common models are role-based access control (RBAC: users get roles, roles get permissions), attribute-based access control (ABAC: rules on user, resource, and context attributes), and relationship-based access control (ReBAC: permissions follow relationships like 'owner of' or 'member of the team that owns'). Large systems often centralize policy in a dedicated service.

Keycard access in an office

Your badge proves who you are (authentication). Whether it opens the server room depends on your role, the time of day, and whether you are on the access list for that room (authorization).

02

When to use it

  • Any multi-user or multi-tenant system.
  • Admin features, sharing, and team permissions.
  • Regulated data requiring least privilege and audit logs.
  • APIs where object IDs appear in URLs (/documents/123).
03

Where it shows up in interviews

Multi-tenant access

Recognize it when: users must only see their organization's data.

  • Design a SaaS platform
  • Design Slack workspaces
Sharing and permissions

Recognize it when: documents shared with users, groups, and links.

  • Design Google Drive
  • Design Notion permissions
04

Where it is used in real software

Google Zanzibar

Google's global authorization system for Drive, YouTube, and Photos uses relationship tuples; open-source versions include SpiceDB and OpenFGA.

AWS IAM

Policies with allow and deny statements evaluated on principal, action, resource, and conditions.

OWASP API Top 10

Broken object level authorization (BOLA / IDOR) is ranked the number one API security risk.

05

Key terms

RBAC
Permissions attached to roles (admin, editor, viewer).
ABAC
Policies evaluate attributes: user.department == resource.department.
ReBAC
Permissions derived from relationships in a graph (Zanzibar).
IDOR / BOLA
Accessing another user's object by changing an ID in the request.
Policy decision point
The service that evaluates authorization policy (for example OPA).
06

How it works, step by step

  1. 1
    Identify the subject

    The authenticated user or service, with its roles and attributes.

  2. 2
    Identify the action and resource

    action = document.edit, resource = document 123 in tenant 7.

  3. 3
    Load context

    Resource owner, tenant, sharing relationships, time, IP.

  4. 4
    Evaluate policy

    Deny by default; allow only if a rule grants it.

  5. 5
    Enforce and audit

    Return 403 (or 404 to hide existence) and log sensitive decisions.

07

RBAC vs ABAC vs ReBAC

Same question: can Ana edit document 123?

Step 1 / 3
ModelHow the answer is computedGood for
RBACAna has role editor, editor has document.editSimple apps, admin consoles
ABACAna.dept == doc.dept AND doc.status != lockedFine-grained, context-aware rules
ReBACAna is member of team X, team X is editor of folder Y, doc in folder YSharing, hierarchies, collaboration

NOWModel: RBAC | How the answer is computed: Ana has role editor, editor has document.edit | Good for: Simple apps, admin consoles

RBAC alone cannot express 'only the owner can edit their document'; most real systems combine roles with ownership or relationship checks.

08

Implementation

type Role = "viewer" | "editor" | "admin";const permissions: Record<Role, string[]> = {  viewer: ["doc.read"],  editor: ["doc.read", "doc.edit"],  admin: ["doc.read", "doc.edit", "doc.delete", "member.manage"],}; function can(user: User, action: string, doc: Doc): boolean {  if (user.tenantId !== doc.tenantId) return false;              // tenant isolation first  if (doc.ownerId === user.id) return true;                       // ownership  const role = doc.members[user.id];                              // per-document role  return role !== undefined && permissions[role].includes(action);} app.patch("/v1/docs/:id", async (req, res) => {  const doc = await docs.get(req.params.id);  if (!doc || !can(req.user, "doc.edit", doc)) return res.status(404).end(); // do not reveal existence  res.json(await docs.update(doc.id, req.body));});
09

Complexity and performance

Check per request< 1-5 ms

Cache policies and relationships.

ReBAC graph walkO(depth)

Bounded with caching.

10

Trade-offs

Central service vs in-app checks

A central policy service gives consistency and audits but adds a network call; in-app checks are fast but drift between services.

403 vs 404

403 is honest; 404 avoids revealing that a resource exists, which matters for private data.

11

Variants and related techniques

Policy as code

Open Policy Agent (Rego) or Cedar evaluate policies separately from application code.

Row-level security

PostgreSQL RLS enforces tenant filters in the database itself.

OAuth scopes

Coarse permissions granted to a client app (read:orders), combined with per-object checks.

12

Common mistakes

  • Checking only that the user is logged in.

    Fix: Check that this user may act on this specific object.

  • Trusting client-side checks.

    Fix: Hiding a button is not authorization; enforce on the server.

  • Forgetting list endpoints.

    Fix: Filter queries by tenant and permissions, not just single-item fetches.

13

Interview questions

What is an IDOR vulnerability and how do you prevent it?

Insecure direct object reference: a user changes /orders/123 to /orders/124 and sees someone else's order. Prevent it by checking ownership or permission for every object access, and scoping queries by tenant and user.

How would you design permissions for Google Docs sharing?

Relationship-based: store tuples like (doc:123, editor, user:ana) and (folder:9, viewer, group:eng), inherit permissions through folders, and evaluate with a Zanzibar-style service with caching.

14

Practice problems

ProblemDifficultyWhat it trains
Design RBAC for an admin dashboardEasyRoles and permissions.
Design tenant isolation for a B2B SaaSMediumTenant scoping at every layer.
Design Google Drive sharingHardReBAC and inheritance.