C
Vibe Coding/Architecture/Lesson 09

Architecture — MSA · Message Queue · Event Sourcing · CQRS · API Gateway

30 min·theory

Architecture — MSA · Message Queue · Event Sourcing · CQRS · API Gateway

🎯 What you'll be able to do after this lesson

After completing this lesson, you'll be confident doing the following three things.

  • ✅ Monolith vs MSA decision checklist with 5 criteria
  • ✅ Visualizing system diagrams with mermaid
  • ✅ Separation of concerns (Presentation · Domain · Data)

Keep the learning objectives as a checklist, and close the lesson once you can answer all of them.

MSA · Message Queue · API Gateway

MSA (Microservices Architecture) vs Monolith:

ItemMonolithMSA
DeploymentAll at onceIndependent per service
TechnologySingle stackPer-service choice (Java·Go·Python)
ScalingScale everythingScale hotspots only
FailureFull outagePartial only
ComplexityLowHigh (network·consistency)
Best forSmall scale·early stageLarge scale·multi-team

Message Queue — asynchronous communication:

QueueUse case
KafkaHigh-volume streams (event sourcing)
RabbitMQGeneral-purpose messaging (RPC·task queue)
SQSManaged (AWS)
NATSLightweight·high performance
Redis StreamsSmall systems

API Gateway — single entry point for MSA:

  • Routing (request → appropriate service)
  • Authentication·authorization (no duplication across services)
  • Rate limiting·caching·logging
  • Examples: Kong·AWS API Gateway·Envoy·Traefik

> 💡 When to use MSA?: 8+ team members · significantly different traffic patterns by domain. Before that: monolith → modularize → extract.

Event Sourcing + CQRS

Event Sourcing — storing events instead of state

  • Traditional: update a row in the users table
  • ES: append UserCreated·EmailChanged to an events table (immutable)
  • Current state = replay of all events

Pros:

  • Complete audit log (who·when·what)
  • Time travel (reproducing past state)
  • Easy to add new read models

Cons:

  • Increased complexity (vs. simple CRUD)
  • Difficult to change event schema (events are immutable)
  • Steep learning curve

CQRS (Command Query Responsibility Segregation):

  • Command (write) — normalized DB, transactions
  • Query (read) — denormalized·cache·search engine

Example: e-commerce store

  • Command: PostgreSQL (order processing·payment)
  • Query: Elasticsearch (product search), Redis (cache)
  • Sync: change events delivered via Kafka

Good fit when:

  • 🟢 Read/write ratio is highly skewed (e.g., 10000:1)
  • 🟢 Complex search and aggregation
  • 🔴 Simple CRUD → overkill

> 💡 ES + CQRS = often used together. Events → converted into various read models.

Modern use cases:

  • Banking: ES is the standard (audit·compliance)
  • E-commerce: ES applied to the order domain only
  • Gaming: recording player actions

Vibe Coding and *Architecture* — Why you need both

Core takeaway

If you just tell an AI "Build it as MSA", it will simply split apart a monolith. What you get is not real MSA but a distributed monolith (the worst of both worlds).

Why AI alone can't handle architecture

LLMs have learned code patterns, not business domains. Where service boundaries lie — and who owns what data — are decisions humans must make.

Bad prompt:
> "Split this monolith into MSA"

→ AI: User Service, Order Service, Payment Service... naive separation.
→ Result: circular calls between services + broken transactions — a real distributed monolith.

Good prompt:
> "Design an MSA with the following business boundaries:
> - Auth Service: user authentication·sessions. Other services receive only a JWT
> - Order Service: order flow. Communicates with Payment via events (no tight coupling)
> - Notification Service: notifications. Other services publish to a Kafka topic
>
> ACID transactions required at: payment. Use the Saga pattern."

→ AI: implements real MSA with clear boundaries.

Decision checklist — Is my project a monolith or MSA?

5 questions scored (0–2 points each, 10 total):

Question0 pts1 pt2 pts
Team size1–3 people4–10 people10+ people
TrafficUnder 10K/day100K/day1M+/day
Deploy frequencyLess than weekly1–3 times/weekOnce/day or more
Tech stack diversitySingle language2–3 languages4+ services in different languages
Failure isolation importanceLowMediumCritical (payment·finance)
  • 0–3 pts → Monolith. Don't worry about anything else. Start with Next.js + one DB
  • 4–6 pts → Monolith with clear module boundaries. Prepare for future extraction
  • 7–10 pts → Consider MSA. But: recommended to start with monolith and extract only the parts that become painful

The truth about "start with a monolith"

> "If you can't build a monolith, what makes you think microservices is the answer?" — Simon Brown

95% of startups are well-served by a monolith + well-separated modules. MSA is warranted only when there are clear pain points.

The trap — hidden costs of MSA

ItemMonolithMSA
Deployment complexity1 unitN units + orchestration
Monitoring1 logDistributed tracing
TransactionsDB ACIDSaga pattern (complex)
DebuggingOne placeNetwork boundaries
Operational headcount1–2 peopleDevOps team required

At the startup stage, MSA = waste of time and money. Consider it when you reach Toss- or Coupang-level traffic.

The pattern for asking AI about architecture

❌ "Is MSA better or is monolith better?" — too abstract

✅ "My project has 3 team members, 5K daily users, 1 deploy per week, and a single Node.js stack. Does MSA make sense here? Analyze it based on the checklist."

→ AI gives an answer tailored to my situation.

Summary

  • AI only knows code patterns. Business boundaries are for humans to decide
  • Diagnose your situation with the 5-question checklist
  • Start with a monolith. MSA only when you truly need it
  • When asking AI, always specify your concrete situation

🤖 Try asking AI like this

Knowing the concepts in this lesson lets you give AI specific instructions. Not a vague "fix it" but a request with vocabulary — that's the starting point for saving tokens.

  • "Before splitting this monolith into MSA, check it against the 5-point checklist"
  • "Draw this system diagram with mermaid"

Why this reduces tokens

Without the concepts, even after receiving AI's response you have to ask "What does that mean?" again. Those follow-up questions eat up tokens. Learn the concepts once and the conversation wraps up in a single exchange.

Architecture — MSA·Message Queue·ES·CQRS - Vibe Coding