Langsung ke konten
Skillpedia
Lain-lain48k Β· #5233

patterns

Fungsinya

Dokumen ini adalah referensi untuk design pattern (pola desain) yang dipakai dalam pemrograman, seperti CQRS, Event Sourcing, dan Saga. Dokumen ini menjelaskan apa itu, kapan digunakan, dan bagaimana cara kerjanya.

Kapan dipakai

  • βœ“Saat Anda ingin mempelajari design pattern.
  • βœ“Untuk memahami cara mengatur sistem yang kompleks.
  • βœ“Saat mencari solusi untuk masalah umum dalam pengembangan software.

Link skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/monopoly/patterns/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/monopoly/patterns/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œJelaskan kepada saya tentang Circuit Breaker pattern.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Dokumen ini mencantumkan dan menjelaskan berbagai design pattern software. Untuk setiap pattern, dokumen ini merinci apa itu, kapan berguna, cara mengimplementasikannya, serta kelebihan dan kekurangannya.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

MONOPOLY β€” Design Patterns Deep Dive

When to Use

  • Use this skill when the task matches this description: Reference document for monopoly patterns.

Table of Contents

  1. CQRS
  2. Event Sourcing
  3. Saga Pattern
  4. Circuit Breaker
  5. Bulkhead
  6. Strangler Fig
  7. Sidecar / Service Mesh
  8. Outbox Pattern
  9. Consistent Hashing
  10. Backpressure
  11. Leader Election
  12. Two-Phase Commit

1. CQRS (Command Query Responsibility Segregation)

What it is: Separate the read model (Query) from the write model (Command) into distinct services, databases, or code paths.

When to use:

  • Read load is 10Γ—+ write load (most web apps)
  • Read queries are complex aggregations over write data
  • Need to optimize read and write paths independently
  • Domain model is complex (DDD contexts)

Implementation:

Write Path:  Client β†’ Command API β†’ Write DB (normalized, PostgreSQL)
Read Path:   Client β†’ Query API  β†’ Read DB (denormalized, Redis / Elasticsearch)
Sync:        Write DB β†’ CDC (Debezium) β†’ Message Queue β†’ Read DB updater

Trade-offs:

  • βœ… Independent scaling of read and write
  • βœ… Optimized schemas for each operation type
  • ❌ Eventual consistency between write and read models
  • ❌ Increased complexity; two models to maintain

Real-world users: Amazon (order service), LinkedIn (feed)


2. Event Sourcing

What it is: Store state as a sequence of immutable events rather than current state. Rebuild current state by replaying events.

When to use:

  • Full audit trail is a regulatory requirement (fintech, healthcare)
  • Need to replay history for debugging or analytics
  • Complex domain with many state transitions
  • Need to derive multiple read projections from same data

Implementation:

Event Store: append-only log (Kafka, EventStoreDB)
Snapshots:   periodic snapshots to speed up state rebuild
Projections: consumers build read models from events

Trade-offs:

  • βœ… Complete audit history; perfect for compliance
  • βœ… Replay and time-travel debugging
  • ❌ Querying current state requires projection maintenance
  • ❌ Event schema evolution is hard
  • ❌ High storage overhead over time

3. Saga Pattern

What it is: Manage distributed transactions across microservices via a sequence of local transactions, each publishing an event. If a step fails, compensating transactions undo previous steps.

Two variants:

  • Choreography: Services react to events autonomously (decentralized)
  • Orchestration: A central Saga Orchestrator coordinates steps (centralized)

When to use:

  • Multi-service workflows where ACID across services is impossible
  • Long-running business transactions (order β†’ payment β†’ inventory β†’ shipping)
  • Need rollback across service boundaries

Choreography Example:

OrderService creates order β†’
  [event: OrderCreated] β†’
    PaymentService charges card β†’
      [event: PaymentProcessed] β†’
        InventoryService reserves stock β†’
          [event: StockReserved] β†’
            ShippingService books courier

Compensating Transactions (on failure):

ShippingService fails β†’
  [event: ShippingFailed] β†’
    InventoryService releases stock β†’
      PaymentService refunds card β†’
        OrderService marks order failed

Trade-offs:

  • βœ… No distributed locking; high availability
  • βœ… Scales well across services
  • ❌ Hard to debug; distributed trace required
  • ❌ Compensating transactions are complex to implement correctly

4. Circuit Breaker

What it is: A proxy that monitors calls to a service. If failure rate exceeds threshold, the circuit "opens" and calls fail fast instead of waiting for timeout.

States:

CLOSED  β†’ calls pass through; monitor failure rate
OPEN    β†’ calls fail immediately; no calls to downstream
HALF-OPEN β†’ let a probe call through; if success, close; if fail, stay open

When to use:

  • Calling any external service (payment gateway, SMS, email)
  • Microservices calling each other
  • Preventing timeout cascade when downstream is slow

Implementation tools: Hystrix (deprecated), Resilience4j, Polly (.NET), Envoy proxy

Thresholds (starting point):

  • Open after 50% failure rate over 10 requests
  • Stay open for 30 seconds
  • Half-open: allow 1 probe request

Trade-offs:

  • βœ… Prevents cascade failures
  • βœ… Gives downstream time to recover
  • ❌ Adds latency overhead for monitoring
  • ❌ Requires fallback behavior when circuit is open

5. Bulkhead

…

Pertanyaan umum

Apa itu 'design pattern'?

Itu adalah solusi yang bisa digunakan kembali untuk masalah umum dalam pengembangan software. Solusi ini membantu membuat kode yang lebih terorganisir, efisien, dan mudah dipelihara.

Apa perbedaan antara CQRS dan Event Sourcing?

CQRS memisahkan operasi baca dan tulis, sedangkan Event Sourcing mencatat semua perubahan sebagai urutan event.

Apa itu 'Saga Pattern'?

Itu adalah cara untuk mengelola transaksi yang melibatkan beberapa service, sehingga semuanya selesai atau dibatalkan dengan benar, meskipun ada satu bagian yang gagal.

Detail

Deskripsi asli dari pembuat

Reference document for monopoly patterns.

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#5233
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa