Chapter 1: Architecture Overview

The Fundamental Challenge

Static websites are, by definition, static. They consist of pre-generated HTML, CSS, and JavaScript files served directly from a web server or CDN. There’s no server-side processing when a visitor requests a page. Comments, however, are inherently dynamic—they’re created by users after the page is published.

This chapter explores the architectural approaches to bridging this gap.

Architecture Patterns

Pattern 1: API Backend + Frontend Widget

The most common approach involves a separate backend service that handles comment storage and retrieval, with a JavaScript widget on your static site that communicates with this backend.

How it works:

Advantages:

Disadvantages:

Pattern 2: Git-Based Comments

This approach treats comments as part of your site’s source code, storing them in your Git repository and rebuilding the site when new comments are approved.

How it works:

Advantages:

Disadvantages:

Pattern 3: Serverless Functions

A lightweight approach using serverless functions (AWS Lambda, Cloudflare Workers, Netlify Functions) to handle comment operations.

How it works:

Advantages:

Disadvantages:

Pattern 4: Static JSON Files

The simplest approach: store comments as static JSON files that are loaded by the browser.

How it works:

Advantages:

Disadvantages:

Pattern 5: Third-Party Backend with Self-Hosted Frontend

A hybrid approach using a managed database service while controlling the frontend and API logic yourself.

How it works:

Advantages:

Disadvantages:

Choosing Your Architecture

Decision Factors

Traffic Volume:

Technical Resources:

Feature Requirements:

Budget:

Hybrid Approaches

You don’t have to choose just one pattern. Many successful implementations combine approaches:

System Components

Regardless of which architecture you choose, your system will need these logical components:

Comment Submission Endpoint

Receives new comments from users, validates them, and initiates storage.

Storage Layer

Persists comments durably. Options discussed in detail in Chapter 2.

Retrieval Mechanism

Fetches comments for display on pages. Must be fast and cacheable.

Moderation Interface

Allows you (or moderators) to review, approve, edit, or delete comments.

Display Component

Frontend code that renders comments on your pages.

Spam Filter

Checks submissions for spam before storage. Detailed in Chapter 4.

Notification System (Optional)

Alerts users to replies or you to new comments.

API Design Considerations

If your architecture includes an API, consider these design decisions:

RESTful vs. GraphQL

Endpoint Structure

Response Format

Rate Limiting

Data Flow Patterns

Write Path (Submission)

  1. User submits comment
  2. Frontend validates basic requirements
  3. Backend receives submission
  4. Spam check performed
  5. Comment stored (pending or approved)
  6. Confirmation returned to user
  7. Notification sent (if applicable)

Read Path (Display)

  1. Page loads
  2. Frontend requests comments
  3. Backend retrieves from storage
  4. Comments returned (possibly cached)
  5. Frontend renders comments
  6. Pagination handled if needed

Moderation Path

  1. New comment triggers notification
  2. Moderator reviews in moderation interface
  3. Decision made (approve/reject/edit)
  4. Comment status updated
  5. Public display updated accordingly

Scalability Considerations

Vertical Scaling

Adding more resources to a single server. Simple but has limits.

Horizontal Scaling

Adding more servers. Requires stateless design and load balancing.

Caching Layers

Database Scaling

Summary

The architecture you choose sets the foundation for everything else. Consider:

Most personal blogs and small sites can start with the simplest approach (static JSON or serverless) and evolve as needs grow. The key is choosing an architecture that you can implement, maintain, and afford.

The next chapter dives deep into storage strategies, exploring where and how to persist your comment data.