System Design Fundamentals

INFO 153B/253B Backend Web Architecture

Week 11: You've Been Building Blocks All Along

Spring 2026 | UC Berkeley School of Information

Today's Agenda

  • Part 1: From Code to Systems Thinking
  • Part 2: The 7 Building Blocks
  • Demo: Assignment 2 as a System Diagram
  • Exploration: Design a URL Shortener
Reminder: Assignment 2 due Friday, April 10th

Part 1

From Code to Systems Thinking

The Big Question

You've built Flask APIs, Dockerized apps, connected databases, and run background workers.

But how do you design a NEW system from scratch?
  • When someone says "build me a URL shortener" — where do you start?
  • When your boss asks for a notification system — what's your approach?
  • You know the tools. Now let's learn the thinking.

Code Writer vs System Thinker

Code Writer

  • "How do I implement this feature?"
  • "What framework should I use?"
  • "Let me find code to copy"
  • Focus: Implementation

System Thinker

  • "What are the requirements?"
  • "What patterns apply here?"
  • "What are the trade-offs?"
  • Focus: Architecture

This course is moving you from left to right.

Patterns Last, Technologies Don't

The Caching Pattern

  • 2005: Memcached — fast key-value lookups
  • 2015: Redis — richer features, same pattern
  • 2020: AWS ElastiCache — managed cloud, same pattern
  • 2026: Whatever's next — still the same pattern
  • Technologies evolve every few years
  • Patterns remain stable for decades
  • Learn the pattern once → apply to any technology

What is a Building Block?

Building blocks are proven system components that appear repeatedly across all modern systems.

  • Technology-agnostic: describe what a component does, not how
  • Universal: Instagram, Netflix, Gmail, Uber all use the same ones
  • Composable: combine them to design any system
  • Timeless: the same blocks have been used for decades

Think of them like LEGO — a small set of standard pieces that build anything.

You Already Know Building Blocks

Your 253B tech stack is building blocks:

Flask Routes
Service
rq Workers
Worker
Redis Queue
Queue
SQLAlchemy / PostgreSQL
Relational Database

Same Blocks, Everywhere

Instagram photo upload uses the same building blocks you used in Week 10:

User uploads photo

[Service] receives the request

[Relational DB] stores photo metadata

[File Store] saves the actual image

[Queue] triggers background processing

[Worker] creates thumbnails, applies filters

[Key Value Store] caches popular photos

Building Blocks vs Technologies

Building Block (Pattern)

  • What: Fast lookup capability
  • Purpose: O(1) data access
  • Focus: Interface & behavior
  • Lifespan: Decades

Technology (Implementation)

  • Examples: Redis, Memcached, DynamoDB
  • Specifics: APIs, configs, pricing
  • Focus: Implementation details
  • Lifespan: Years
System thinkers say: "We need a Key Value Store for caching"
Then choose: "Let's use Redis because..."

What Drives Your Design?

Three external forces shape every system:

User

Human interactions
Your Flask API endpoints
Login, search, upload

External Service

Third-party APIs
Payment (Stripe)
Email (SendGrid)

Time

Scheduled triggers
Cron jobs, recurring tasks
Daily reports, reminders

  • These forces determine which building blocks you need
  • Start every design by asking: Who/what interacts with this system?

Part 2

The 7 Building Blocks

The 7 Building Blocks

Task Blocks (Do Work)

Service

Worker

Storage Blocks (Hold Data)

Key Value Store

Queue

Relational Database

File Store

Vector Database

2 ways to do work + 5 ways to store data = every system

Service Request/Response Processing

  • What it does: Handles synchronous requests, returns immediate responses
  • Mental model: A restaurant server — takes your order, brings back results
  • Perfect for: API endpoints, user-facing operations, real-time interactions
  • Not ideal for: Long-running processes, heavy computations
Your 253B experience: Every @app.route you've written in Flask is a Service.
@app.route('/tasks', methods=['POST'])
def create_task():       # This IS a Service
    data = request.json   # Receive request
    task = Task(**data)   # Process it
    db.session.add(task)  # Store result
    return task, 201      # Immediate response

Worker Background Processing

  • What it does: Handles long-running tasks asynchronously
  • Mental model: Kitchen staff — works behind the scenes on complex dishes
  • Perfect for: Background jobs, data processing, scheduled tasks
  • Not ideal for: User-facing requests, immediate responses
Your 253B experience: Every @job function you've written with rq is a Worker.
@job('default', connection=redis)
def send_notification(notification_id):  # This IS a Worker
    notification = Notification.query.get(notification_id)
    # Takes time - that's fine, we're in background
    deliver(notification)
    notification.status = 'delivered'
    db.session.commit()

The Fundamental Async Pattern

Service handles NOW. Worker handles LATER. Queue connects them.

User sends request

[Service] validates, stores in DB, returns 202 Accepted

[Queue] holds the job message

[Worker] picks up job, processes it
You built this exact pattern in Week 8 (rq tasks) and Week 10 (Notification Hub).
  • User gets an immediate response (fast UX)
  • Heavy work happens in the background (scalable)
  • If a Worker crashes, the Queue retains the job (reliable)

5 Storage Building Blocks

Building Block Optimized For 253B Tech
Key Value Store Fast lookups, caching New concept
Queue Ordered message flow Redis Queue (rq)
Relational Database Structured data + relationships PostgreSQL
File Store Large files (images, video) New concept
Vector Database Similarity search (AI) New concept

You've used 2 of 5. Let's see all of them.

Key Value Store Fast Dictionary Lookups

  • What it does: Fast data retrieval using unique keys — O(1) performance
  • Mental model: Coat check — give a ticket (key), get back your coat (value)
  • Perfect for: Caching, sessions, counters, configuration
  • Limitation: No complex queries, no relationships — simple key-based access only
Real-world examples: Redis, Memcached, DynamoDB
User sessions, shopping cart contents, cached API responses, real-time counters

Queue Ordered Message Processing

  • What it does: Manages ordered message flow — first in, first out (FIFO)
  • Mental model: Line at a coffee shop — first in line, first served
  • Perfect for: Task coordination, background job scheduling, event processing
  • Limitation: Messages are temporary, not for permanent storage
Your 253B experience: Redis Queue from Week 8.
queue.enqueue(send_notification, notification_id)
  • The bridge between Services and Workers
  • Provides reliability — if a Worker crashes, the message stays in the Queue
  • Enables decoupling — Services and Workers don't need to know about each other

Relational Database Structured Data with Relationships

  • What it does: Stores structured data with ACID guarantees and complex relationships
  • Mental model: Filing cabinet with cross-references — organized, connected, reliable
  • Perfect for: Business data, financial transactions, user accounts, complex queries
  • Limitation: Slower than KV Store, requires fixed schema, not great for unstructured data
Your 253B experience: SQLAlchemy + PostgreSQL from Week 7.
Tasks belong to Categories. Users have Orders. Relationships.
class Task(db.Model):                  # Structured data
    category_id = db.Column(
        db.Integer,
        db.ForeignKey('category.id'))   # Relationship!
    category = db.relationship('Category', back_populates='tasks')

File Store Large File Storage

  • What it does: Stores and retrieves large files with metadata
  • Mental model: Warehouse — stores big items with tracking info
  • Perfect for: Images, videos, documents, backups, global content delivery
  • Not ideal for: Structured data, complex queries, transactions
New building block! You haven't used this in 253B yet.
  • Real-world tech: AWS S3, Google Cloud Storage, Azure Blob Storage
  • Every photo on Instagram, every video on YouTube — File Store
  • Often paired with a Relational DB: file in File Store, metadata in database

Vector Database Similarity Search

  • What it does: Finds similar items using AI embeddings and semantic search
  • Mental model: Smart librarian — finds books similar to what you're looking for
  • Perfect for: AI applications, recommendations, semantic search, image similarity
  • Not ideal for: Exact matches, simple lookups, structured business data
New building block! The newest addition — designed for the AI era.
  • Real-world tech: Pinecone, Weaviate, pgvector, ChromaDB
  • "Customers who bought X also bought Y" — Vector Database
  • "Find documents about this topic" (even without exact keyword match)

Choosing the Right Building Block

5 questions to systematically select the right block:

  1. Is this about doing work or storing data?
    → Task block vs Storage block (eliminates half your options)
  2. Does it need an immediate response?
    → Service (now) vs Worker (later)
  3. How will the data be accessed?
    → By key? By query? By similarity? By file name?
  4. What are the performance requirements?
    → Speed (KV Store) vs Features (Relational DB) vs Scale (File Store)
  5. What are the data relationships?
    → Simple key-value? Complex with foreign keys? Unstructured files?

Common Anti-Patterns

Using a Relational DB for caching
Like using a filing cabinet to temporarily hold your coat — works, but slow and wasteful.
→ Use a Key Value Store instead.
Storing large files in your database
Like trying to fit a couch in a filing cabinet drawer — doesn't fit well.
→ Use a File Store for the file, database for the metadata.
Using a Service for long-running tasks
You experienced this in Week 8! The API blocked while processing.
→ Use Service + Queue + Worker pattern.
Rule of thumb: Match the building block to its strengths, not your familiarity.

Your Complete System — In Building Blocks

Building Block Technology Role in Your System
Service Flask Receives HTTP requests, validates, responds
Relational DB PostgreSQL Stores tasks, categories, relationships
Queue Redis Holds background job messages
Worker rq Processes jobs in the background

All wrapped in Docker Compose

  • 4 building blocks working together: Service, Worker, Queue, Relational DB
  • Docker isn't a building block — it's the deployment wrapper
  • Marshmallow isn't a building block — it's a validation layer on the Service
  • This same architecture scales from your laptop to millions of users

Key Takeaways

  1. System thinkers think in patterns, not specific technologies
  2. 7 building blocks (2 Task + 5 Storage) compose every system
  3. You already know 4 from this semester — Flask, rq, Redis Queue, PostgreSQL
  4. Requirements first, technology second — always
  5. The same patterns scale from your Assignment 2 to Instagram
You've been a system thinker all along.
Now you have the vocabulary and framework to design anything.

Demo

Assignment 2 as a System Diagram

Assignment 2: Task Manager API

Let's diagram it using building blocks...

[User]
↓ HTTP Request
[Service: Flask API] — validates with Marshmallow
↓                   ↓
[Relational DB: PostgreSQL]    [Queue: Redis]
Tasks & Categories                 ↓
                           [Worker: rq]
                          Due date reminders

(Live demo — draw this step by step on the board)

In-Class Exploration

Design a URL Shortener

Your Task: Design a URL Shortener

Scenario: Your startup needs a link shortener service (like bit.ly). Design the system using building blocks.

The 5 Requirements

  1. Generate unique short URLs that redirect to long URLs
  2. Handle large amounts of load (what if a link goes viral?)
  3. Handle concurrent requests without compromising performance or data consistency
  4. Track and log click counts and basic usage metrics per short URL
  5. Handle invalid or expired URLs with appropriate error responses

Exploration Steps

  1. Copy the template (link on bCourses / posted in chat)
  2. Identify building blocks — which of the 7 does each requirement need?
  3. Draw the system diagram — place building blocks and show data flow
  4. Label everything — building block type + what it stores/processes
  5. Bonus: Map technologies — which specific tech would you use for each block?
Template: Google Drawings Template
File → Make a Copy, then start designing!

Time: ~40 minutes | Format: Small groups (2-3)

Hints: Building Block Selection

Requirement Think About...
Generate & redirect URLs What receives the request? Where are mappings stored?
Handle viral load How do you make redirects fast? What if the DB is too slow?
Concurrent requests Which storage block guarantees consistency?
Track click metrics Should tracking block the redirect? What pattern avoids that?
Handle invalid/expired URLs Where do you check validity? What does the Service return?

Show this slide after ~15 minutes if groups need a nudge.

What's Next

  • Week 12: Technology Mapping — deeper into design patterns and real-world case studies
  • Assignment 2: Due Friday, April 10th — you now see it's 4 building blocks!