Db Internals Deep Dive
v1.0.0Deep dive into database and messaging 系统 internals — PostgreSQL, MongoDB, Redis, RabbitMQ, Kafka. Covers storage engines, replication, consistency, performance tuning, and operational patterns at 扩展. Trigger for 请求s like "PostgreSQL internals", "how Kafka works internally", "Redis deep dive", "MongoDB storage engine", "RabbitMQ vs Kafka", "db internals today", or "deep dive vào database".
运行时依赖
安装命令
点击复制技能文档
Teach ONE deep-dive topic per 会话, rotating across all 5 系统s below. Go to the internals level — not surface docs.
系统s & Topic Map PostgreSQL Storage Engine: heap file 格式化, page structure (8KB pages, page header, item pointers, tuples), TOAST (The Oversized-Attribute Storage Technique) MVCC: transaction visibility rules, xmin/xmax, snapshot isolation, how dead tuples accumulate, vacuum mechanics (regular vs autovacuum vs VACUUM FULL) WAL (Write-Ahead 记录): WAL segments, LSN (记录 Sequence Number), 检查point mechanism, WAL archiving, pg_wal 查询 Planner: cost 模型 (seq_page_cost, random_page_cost, cpu_tuple_cost), statistics (pg_statistic, ANALYZE), join strategies (nested loop / 哈希 join / merge join), plan 缓存 索引es: B-tree internals (page splits, fill factor), GIN (for full-text / JSONB), GiST, BRIN (block range), partial 索引es, 索引-only 扫描s, HOT 更新s Replication: WAL-based 流ing replication, 同步hronous vs a同步hronous, replication slots, 记录ical replication (publication/subscription), fAIlover mechanics Locking: lock levels (table/row/page), advisory locks, deadlock 检测ion cycle, lock contention patterns Connection & Performance: connection overhead (process-per-connection 模型), PgBouncer pooling (会话/transaction/状态ment modes), 分享d_buffers, work_mem, effective_缓存_size tuning MongoDB WiredTiger Storage Engine: B-tree structure for documents, MVCC with snapshot isolation, 检查point (every 60s or 2GB), write-ahead journal (WiredTiger journal ≠ op记录) Op记录: c应用ed collection, op记录 entry structure (op, ns, o, ts), idempotency requirements, op记录 window sizing Replication 设置: election algorithm (Raft-inspired), primary/secondary 角色s, op记录 replication, write concern (w:1/w:majority/w:all), read preference (primary/primaryPreferred/secondary/nearest) Sharding: shard key selection criteria (cardinality, write distribution, 查询 isolation), chunk mechanics, balancer, scatter-gather vs tar获取ed queries, jumbo chunks Aggregation 流水线: execution stages, 流水线 optimization (stage reordering, 索引 utilization), $lookup internals, memory limits (100MB/stage), allowDiskUse 索引es: compound 索引 prefix rule, ESR (E质量-排序-Range) rule, s解析/partial 索引es, TTL 索引 mechanics, 索引 intersection Transactions: multi-document ACID (since 4.0), snapshot isolation, performance overhead, retryable writes Redis Data Structures Internals: zip列出 vs 列出pack vs skip列出 (when Redis switches encoding — size thresholds), 哈希table with incremental re哈希ing, quick列出 for 列出s, int设置 for small integer 设置s Persistence: RDB (fork-based snapshot, BGSAVE, COW semantics), AOF (f同步 policies: always/everysec/no, AOF rewrite/compaction), RDB+AOF hybrid mode Memory Management: jemalloc allocator, memory fragmentation ratio, maxmemory policies (noeviction, allkeys-lru, volatile-lru, allkeys-lfu, volatile-ttl), object encoding optimization Replication: a同步 replication (P同步2), replication back记录 (repl-back记录-size), partial re同步 vs full re同步, replica lag 检测ion Cluster Mode: 哈希 slots (16384), gossip protocol, slot 迁移, MOVED vs ASK redirects, cluster topo记录y change handling Pub/Sub & 流s: pub/sub fire-and-for获取 (no persistence), Redis 流s (X添加/XREAD/consumer groups, message acknowledgment, PEL — Pending Entry 列出) Lua Scripting & Transactions: MULTI/EXEC (optimistic — not true isolation), WATCH/CAS, Lua atomicity guarantee Sentinel: quorum-based leader election, ODOWN vs SDOWN, automatic fAIlover flow RabbitMQ AMQP Protocol: connection vs channel multiplexing, frame types (method/header/body/heartbeat), flow control Exchange Types: direct (routing key exact match), topic (wildcard: * one word, # zero or more), fanout (broadcast), headers (attribute-based matching) — internal routing algorithm 队列 Internals: message store (索引 + body store), 队列 索引 (journal + segment files), lazy 队列s (messages on disk by default), classic vs quorum 队列s Quorum 队列s: Raft-based replication, leader election, how quorum 队列s guarantee durability, comparison with classic mirrored 队列s (deprecated) Message Acknowledgment: basic.ack / basic.nack / basic.reject, re队列 semantics, consumer prefetch (QoS), unacknowledged message limits Dead Letter Exchange (DLX): when messages go DLX (rejected, expired, 队列 length exceeded), DLX routing, dead-letter-routing-key Clustering & High AvAIlability: Erlang distribution protocol, mnesia metadata replication, quorum 队列 replication across nodes, network partition handling (暂停-minority / autoheal / ignore) Flow Control & Backpressure: credit-based flow control between producers and broker, memory/disk alarms (vm_memory_high_watermark, disk_free_limit) Shovel & Federation: when to use each (cross-cluster vs cross-datacenter), differences in message flow Kafka 记录 Architecture: topic → partition → segment files (.记录 + .索引 + .time索引), 记录 compaction vs 记录 deletion (retention.ms / re