본문으로 건너뛰기
cccskills
무료GitHub에 공개

nw-sd-patterns

Core distributed systems patterns - load balancing, caching, sharding, consistent hashing, message queues, rate limiting, CDN, Bloom filters, ID generation, replication, conflict resolution, CAP theorem

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구AWSRedisSnowflake
설치 방법 보기

포함된 파일(1)

  • SKILL.md8.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Core Distributed Systems Patterns

Load Balancing

Problem: single server can't handle all traffic.

Approaches: Round Robin (simple, ignores load) | Weighted Round Robin (accounts for capacity) | Least Connections (fewest active) | IP Hash (session affinity) | Layer 4/transport (IP/port, fast) | Layer 7/application (HTTP-aware, smarter)

Placement: client-to-web | web-to-app | app-to-database

Trade-offs: LB itself is SPOF -- use active-passive pair | session affinity complicates horizontal scaling -- prefer stateless servers | health checks critical

Caching

Problem: repeated DB reads are slow.

Strategies: Cache-aside/lazy loading (app checks cache, fills on miss -- most common) | Write-through (write cache+DB simultaneously) | Write-behind (cache only, async to DB) | Read-through (cache fronts DB transparently)

Cache-aside pattern: Read: cache.get(key) -> hit? return : db.read -> cache.set -> return | Write: db.write -> cache.delete(key)

Eviction: LRU (most common) | LFU (skewed access) | TTL (time-based)

Problems: thundering herd (many misses simultaneously -- use locking/coalescing) | cache penetration (non-existent keys -- Bloom filter or cache null) | cache avalanche (mass expiration -- jittered TTLs) | size cache based on working set, not total data

Database Replication

Master-Slave: all writes to master, reads to replicas | replication lag = eventual consistency | master fails: promote replica

Multi-Master: writes to any node, conflict resolution required | better write availability, much more complex | suitable for multi-region

Trade-offs: sync replication = consistency but higher write latency | async = lower latency but data loss risk on failure

Database Sharding

Problem: single DB can't handle write volume or data size.

Strategies: Hash-based (hash(key) % N -- even but resharding painful) | Range-based (ranges, can have hotspots) | Directory-based (lookup table, flexible but SPOF)

Partition key: must distribute data AND queries evenly | must be in most queries | common: user_id, tenant_id, region

Challenges: resharding (consistent hashing helps) | celebrity/hotspot problem | cross-shard joins (expensive -- denormalize) | referential integrity (enforce in app) | schema changes across all shards

Consistent Hashing

Problem: traditional hash(key) % N remaps almost all keys when N changes.

How: hash output space as ring (0 to 2^32-1) | servers at positions on ring | keys walk clockwise to first server | adding/removing server affects only adjacent keys

Virtual nodes: each physical server gets 100-200 positions | ensures even distribution | handles heterogeneous capacities

Used in: DynamoDB, Cassandra, Discord, Akamai CDN

Message Queues

Problem: tight coupling; spikes overwhelm downstream.

Properties: decoupling | buffering (absorbs spikes) | async processing | guaranteed delivery

Patterns: Point-to-point (one consumer per message) | Pub/Sub (all subscribers get message) | Dead letter queue (failed messages for debugging)

When: email/notification sending | image/video processing | analytics ingestion | cross-service communication | any op where user doesn't need immediate result

Technologies: Kafka (high throughput, log-based, event streaming) | RabbitMQ (flexible routing, task queues) | SQS (managed, AWS) | Redis Streams (lightweight)

Rate Limiting

Problem: protect services from abuse and cascading overload.

AlgorithmMechanismProsCons
Token Buckettokens refill at fixed rateallows bursts, simplememory per user
Leaking Bucketqueue with fixed processing ratesmooth outputno burst flexibility
Fixed Windowcount per time windowsimpleburst at edges
Sliding Window Logtrack each request timestampprecisememory-intensive
Sliding Window Counterhybrid fixed + weightedgood balanceapproximate

Token Bucket is industry standard (AWS, Stripe, GitHub). Implementation: API gateway or per-service | Redis counters with TTL | return 429 with Retry-After and X-RateLimit headers

CDN

Problem: static content from origin adds latency for distant users.

How: assets cached at edge servers worldwide | DNS routes to nearest edge | cache miss fetches from origin

Push vs Pull: Push (upload to CDN, infrequent changes) | Pull (CDN fetches on first request, simpler)

Invalidation: URL versioning (preferred) | CDN API purge | TTL expiration

Bloom Filters

Problem: quickly check "is X in set?" without storing full set.

How: bit array + k hash functions | insert sets k bits | query checks k bits | false positives possible, false negatives impossible

Used for: cache penetration prevention | duplicate URL detection (crawlers) | spam filtering

Config: 10 bits per element ~ 1% false positive rate | cannot delete (use Counting Bloom Filter)

Unique ID Generation

ApproachSortableSizeCoordinationThroughput
UUID v4No128bNoneUnlimited
DB auto-incYes64bHighLimited
Ticket serverYes64bMediumLimited
SnowflakeYes64bMinimalVery high

Snowflake: [1 unused | 41 timestamp | 5 datacenter | 5 machine | 12 sequence] -- ~4M IDs/sec/DC | clock sync via NTP is Achilles heel

Fan-out Strategies

Fan-out on write (push): post immediately written to all followers' feeds | read is instant | expensive for celebrities

Fan-out on read (pull): feed computed at read time | write is fast | read is slow

Hybrid (production): push for normal users | pull for celebrities (>10K followers)

Real-time Communication

Long Polling: server holds request open until data or timeout | simple, resource-intensive

WebSocket: full-duplex persistent | low latency | stateful (complicates LB -- need sticky sessions)

SSE: server pushes over HTTP | unidirectional | auto-reconnect | simpler for notification/feed

Geohashing and Spatial Indexing

Geohash: encodes lat/lon to string, nearby share prefix | precision by length (4=39km, 6=1.2km, 8=38m) | boundary problem: query target + 8 neighbors

Quadtree: recursive subdivision into 4 quadrants | adaptive to density | in-memory, 200M items ~1.7GB

Geohash vs Quadtree: geohash simpler (string prefix), DB-friendly | quadtree adaptive to density, in-memory only

Data Replication Strategies

Single-leader: one primary writes, replicas read | simple but SPOF

Multi-leader: multiple write nodes, conflict resolution | better for multi-DC

Leaderless (Dynamo): any node reads/writes | quorum W+R>N | W=1,R=N fast writes | W=N,R=1 fast reads | W=R=N/2+1 balanced | anti-entropy + read repair

Conflict Resolution

LWW: timestamp-based, simple but lossy | Vector clocks: detect conflicts, app resolves | CRDTs: auto-merge data types | Application-level: present to user (like Git)

CAP Theorem

CP (consistency): reject writes during partition | HBase, MongoDB, Redis Cluster | financial transactions

AP (availability): accept writes, resolve later | Cassandra, DynamoDB, CouchDB | social feeds, shopping carts

Real question: "what happens during network partition?" | most systems need availability for reads, consistency for certain writes | tunable consistency (Cassandra) gives flexibility

Write-Ahead Log (WAL)

Before applying mutation, write to append-only log | acknowledge to client | periodically apply to data structure | on crash: replay from last checkpoint. Used in PostgreSQL, MySQL, Cassandra, Kafka.

Gossip Protocol

Each node maintains member list with heartbeat counters | periodically exchanges state with random peer | propagates in O(log N) rounds. Used for membership, failure detection, config propagation.

Trie (Prefix Tree)

Each node = character, root-to-leaf = string | optimizations: compress single-child chains, cache top results at each node, shard by first character. Used in: search autocomplete, spell checking, IP routing.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Review dimensions for validating agent quality - template compliance, safety, testing, and priority validation

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

Review dimensions for validating agent quality - template compliance, safety, testing, and priority validation

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

Review dimensions for acceptance test quality - happy path bias, GWT compliance, business language purity, coverage completeness, walking skeleton user-centricity, priority validation, observable behavior assertions, traceability coverage, and walking skeleton boundary proof

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

Detailed 5-phase workflow for creating agents - from requirements analysis through validation and iterative refinement

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

5-layer testing approach for agent validation including adversarial testing, security validation, and prompt injection resistance

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

Architectural style selection decision matrices, trade-off analysis, structural enforcement rules, and combination patterns. Load when choosing or evaluating architecture styles.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

nWave-ai/nWave6202026년 9월 16일 업데이트

nWave-ai의 스킬 모두 보기

이 스킬의 문제 신고