A Production Engineering Guide from Architecture to Operations
Introduction
- What This Book Covers
- How to Use This Book
- Version Context
- Prerequisites
- Why ClickHouse Is Different
Chapter 1: Why ClickHouse at Scale
- Columnar Storage and the Analytics Workload
- ClickHouse in the Data Stack
- Performance Characteristics: Why It Is So Fast
- What ClickHouse Is Not Built For
- Real-World Scale: Production Deployments in the Field
Chapter 2: Architecture and Internals
- Request Flow from Client to Disk
- The MergeTree Storage Engine Family
- Query Execution Engine and Pipelines
- Memory Management and Allocations
- Single-Threaded Design Philosophy
Chapter 3: MergeTree Deep Dive
- Data Parts and Part Levels
- The Merge Process and Background Merges
- Parts Metadata and the Parts Database
- Out-of-Order Inserts and Data Reordering
- MergeTree Variants and Their Trade-Offs
Chapter 4: Data Modeling for ClickHouse
- The Importance of the ORDER BY Clause
- Primary Key Design and Sparse Indexing
- Choosing Partition Keys Wisely
- Nested Data and Flat Tables
- Schema Design Anti-Patterns
Chapter 5: Partitioning Strategy
- How Partitions Work in ClickHouse
- Partition Granularity: Too Fine vs Too Coarse
- Time-Based Partitioning Patterns
- Partition Pruning and Query Performance
- Partition Operations and Maintenance
Chapter 6: Indexing Beyond Primary Keys
- Granules and the Primary Key Index
- Bloom Filters for Non-Key Columns
- Skip Indices: MINMAX, SET, and TEXT
- Full-Text and Spell Checking Indices
- Secondary Indexes and When They Matter
Chapter 7: Compression and Storage Efficiency
- Codecs and Compression Algorithms
- Compression Level and Speed Trade-Offs
- Per-Column Compression Configuration
- Dictionary Encoding and LZ4HC
- Measuring and Optimizing Storage Ratios
Chapter 8: Storage Engines Beyond MergeTree
- Log Family: Log, Stripelog, Tinylog
- Memory and Null Engines
- Dictionary Engine and External Dictionaries
- View Engines and Summary Engines
- Join and Aggregating Engines
Chapter 9: Disks, Volumes, and Storage Policies
- Storage Disks Configuration
- Storage Policies and Volumes
- Tiered Storage: Hot and Cold Tiers
- Local Disk vs Network Attached Storage
- Storage Policy Lifecycle Management
Chapter 10: Object Storage and S3 Integration
- ClickHouse as an S3 Native Database
- HDFS and S3 Native Formats
- Iceberg, Hudi, and Delta Lake Integration
- Storage Policy with S3 Tiers
- Performance and Cost Considerations for Cloud Storage
Chapter 11: Replication with ReplicatedMergeTree
- ReplicatedMergeTree Architecture
- ZooKeeper-Backed Replication
- Consistency Guarantees and Trade-Offs
- Handling Replica Failures
- Replication Lag and Monitoring
Chapter 12: ZooKeeper and ClickHouse Keeper
- The Role of ZooKeeper in ClickHouse
- ClickHouse Keeper as a Drop-In Replacement
- ZooKeeper Ensemble Sizing and Configuration
- Performance Tuning for Coordination
- Migrating from ZooKeeper to Keeper
Chapter 13: Distributed Tables and Sharding
- How Distributed Tables Work
- Shard Key Design and Data Distribution
- Uniform vs Weighted Sharding
- Distributed Query Execution Flow
- Handling Skewed Data Distribution
Chapter 14: Cluster Topology Design
- Single-Node to Multi-Shard Progression
- Shard and Replica Sizing
- Network Topology Considerations
- Multi-Zone and Multi-Region Clusters
- Cluster Definition Management
Chapter 15: High-Throughput Ingestion Patterns
- INSERT Performance Optimization
- Batch Insertion Best Practices
- HTTP Interface and Protocols
- File-Based Loading and CSVNG
- Insert Quotas and Rate Limiting
Chapter 16: Kafka Integration
- Kafka Engine Configuration
- Consumer Groups and Offset Management
- Real-Time Materialized Views from Kafka
- Backpressure and Lag Handling
- Error Handling and Dead Letter Queues
Chapter 17: Materialized Views and Projections
- Materialized View Types and Triggers
- AggregatingMergeTree for Pre-Aggregations
- Projections for Query Acceleration
- Refresh Strategies and Data Consistency
- Maintenance Overhead and Trade-Offs
Chapter 18: Mutations, TTLs, and Data Lifecycle
- ALTER TABLE DELETE and UPDATE Operations
- Mutation Execution and Performance Impact
- TTL Policies for Automatic Data Expiry
- Moving Data Between Tiers
- Minimizing Mutation Workloads
Chapter 19: Query Execution and Optimization
- Reading EXPLAIN Plans
- Query Pipeline and Parallelism
- Join Optimization Strategies
- Subquery and CTE Optimization
- Vectorized Execution and SIMD
Chapter 20: Resource Management and Concurrency
- Memory Limits and Query Control
- Max Concurrent Queries and Settings
- User Quotas and Resource Pools
- Query Priorities and Throttling
- Preventing Noisy Neighbor Problems
Chapter 21: Distributed Query Optimization
- Distributed Query Execution Flow
- Local and Remote Parts Execution
- Join Strategies Across Shards
- Distributed Aggregations
- Network and Data Movement Optimization
Chapter 22: Hardware and Capacity Planning
- CPU Characteristics and Workloads
- Memory Requirements and Allocation
- Storage Selection: NVMe, SSD, and HDD
- Network Bandwidth and Latency
- Capacity Planning Framework
Chapter 23: Cloud Deployment and Kubernetes
- ClickHouse Cloud vs Self-Managed
- Kubernetes Deployment Patterns
- StatefulSet Configuration for ClickHouse
- Helm Charts and ClickHouse Operator
- Cloud Provider Integration and Best Practices
Chapter 24: Observability and Monitoring
- System Tables and Metrics
- Prometheus Integration
- Alert Rules and Thresholds
- Distributed Tracing for Queries
- Log Collection and Analysis
Chapter 25: Backup, Restore, and Disaster Recovery
- Backup Strategies for ClickHouse
- Disk-Based Backup Methods
- S3 and Remote Backup Targets
- Restore Procedures and Testing
- Disaster Recovery Runbooks
Chapter 26: High Availability and Failure Modes
- Availability Requirements and SLAs
- Failure Mode Analysis
- Load Balancing Strategies
- Node Failure Recovery Procedures
- Consistency and Availability Trade-Offs
Chapter 27: Security and Multi-Tenancy
- Authentication Mechanisms
- Role-Based Access Control
- Network Security and Encryption
- Secrets Management Integration
- Multi-Tenancy Patterns
Chapter 28: Upgrades, Migrations, and Operational Procedures
- Understanding Version Compatibility
- Zero-Downtime Upgrade Procedures
- Migrating Clusters and Topologies
- Schema Evolution Strategies
- Operational Playbooks and Checklists
Chapter 29: Troubleshooting and Incident Response
- Troubleshooting Methodology
- Diagnosing Slow Queries
- Memory and Resource Exhaustion
- Replication and ZooKeeper Issues
- Incident Response Runbooks
Chapter 30: Performance Benchmarking and Cost Optimization
- Benchmarking Methodology and Tools
- TPC-H and TPC-DS Benchmarks
- Workload Profiling and Analysis
- Cost Modeling for ClickHouse Clusters
- Optimization Techniques for Cost Reduction
Chapter 31: Architectural Patterns and Real-World Deployments
- Real-Time Analytics Patterns
- Log and Event Analytics Architectures
- Time-Series Data Architectures
- Data Lakehouse Integration Patterns
- Lessons from Petabyte-Scale Deployments
Conclusion: The Path Forward
- Core Principles Recap
- Emerging Trends and Features
- When ClickHouse Is and Is Not the Right Choice
- Building Institutional Knowledge