Skip to content

Pattern trong các hệ phân tán

Các hệ thống nhắn tin và giao dịch throughput cao đẩy các pattern throughput tới mức cực hạn.

PatternDự ánTại đâuTác dụng
Ring BufferLMAX DisruptorRingBuffer.javaCấu trúc dữ liệu cốt lõi — 6M lệnh/giây tại LMAX Exchange
Batch ProcessingApache KafkaRecordAccumulator.javaGom record thành lô theo partition để tăng throughput
Circuit BreakerNetflix HystrixHystrixCircuitBreaker.javaCircuit breaker 3 trạng thái cho phục hồi microservice
Circuit BreakerSony gobreakergobreaker.goCircuit breaker Go với phát hiện cũ dựa trên generation
BackpressureReactive StreamsSubscription.javaSpec kiểm soát luồng kiểu pull request(n)
Write-Ahead Logetcdwal.goWAL đồng thuận Raft — nguồn sự thật cho state phân tán
Write-Ahead LogPostgreSQLxlog.cWAL transaction để khôi phục crash, replication, PITR
MVCCPostgreSQLheapam_visibility.cHeapTupleSatisfiesMVCC — kiểm tra hiển thị cô lập theo snapshot
MVCCetcdkvstore.goKho key-value đa phiên bản chạy config Kubernetes
Consistent Hashinggroupcacheconsistenthash.goVòng hash với virtual replica cho cache phân tán
Actor ModelAkkaActor.scalatrait Actor — concurrency hướng thông điệp cho JVM
Actor ModelErlang/OTPerl_process.hStruct process BEAM VM — actor nhẹ với mailbox
Rate LimiterNginxngx_http_limit_req_module.cLeaky bucket rate limiting cho request HTTP
Logical Clocketcdmvcc/revision.goBộ đếm revision tăng dần để sắp xếp sự kiện qua cluster
Logical ClockLevelDBdb_impl.cc sequence numberSequence number sắp xếp mọi thao tác ghi không cần wall-clock
Retry BackoffKubernetesbackoff.goBackoff khởi động lại pod, retry API server với delay tăng cấp số nhân
TombstoneCassandraTombstone markersMarker xoá trong việc lan truyền xoá phân tán
LSM TreeLevelDBdb_impl.ccĐệm ghi trong bộ nhớ, flush thành file đã sắp xếp, compaction ở background
CheckpointingPostgreSQLcheckpointer.cSnapshot state định kỳ giới hạn thời gian replay WAL khi khôi phục

Cách chúng kết hợp: Một thao tác ghi phân tán

Khi client ghi một key vào database phân tán như etcd, các pattern móc nối nhau qua toàn bộ đường đi:

Client: PUT /key "value"
1
Rate Limiter

The gateway applies a token bucket to prevent any single client from overwhelming the cluster.

2
Consistent Hashing

The router determines which node owns this key. Virtual nodes ensure load stays balanced even when nodes join/leave.

3
Write-Ahead Log

Before modifying state, the leader appends the operation to a WAL on disk. If the process crashes, replay recovers state.

4
Logical Clock

The write gets a monotonic revision number. No wall-clock sync needed — all nodes agree on ordering via the revision.

5
MVCC

The new version is stored alongside old versions. Concurrent readers see a consistent snapshot without blocking the write.

6
Checkpointing

Periodically, the system takes a snapshot. Future crash recovery replays only the WAL entries after the last checkpoint.

Các pattern tạo thành một pipeline bền vững: rate limit bảo vệ hệ thống, consistent hashing định tuyến request, WAL đảm bảo bền vững, logical clock sắp xếp sự kiện, MVCC cung cấp cô lập và checkpoint giới hạn thời gian khôi phục.

Đọc thêm

Released under the MIT License.