Architecture Diagram
Overview
BuildBuddy stores several types of data with different characteristics and requirements. The architecture separates structured metadata from large binary data, using appropriate storage systems for each.Data Types
Structured Metadata
Stored in relational database: Invocation Data:- Invocation ID, status, timing
- User, commit SHA, branch
- Command, pattern, exit code
- Build metadata and workspace status
- Target labels and IDs
- Target status and timing
- Rule type and language
- Tags and configuration
- Action IDs and configurations
- File references (digests)
- Test shard/run/attempt information
- Execution metadata
- User accounts and authentication
- Organization memberships
- API keys and permissions
- Usage quotas and billing
- Executor assignments
- Task queue state
- Execution timing and status
Binary Blob Data
Stored in object storage: Build Artifacts (CAS - Content Addressable Storage):- Compiled binaries
- Generated source files
- Build intermediates
- Input files
- Bazel build logs
- Test outputs (stdout/stderr)
- Execution logs
- Profiler outputs
- Test logs and outputs
- Test result files
- Coverage reports
- Test XML/JSON results
- Action results (mappings)
- Output file references
- Execution metadata
Storage Systems
Relational Database
Supported Databases:- MySQL 5.7+
- PostgreSQL 12+
- SQLite (for local development)
- Normalized schema for metadata
- Indexes on common query patterns
- Foreign keys for referential integrity
- Partitioning for large tables
- Connection pooling
- Read replicas for query scaling
- Query optimization and indexing
- Regular vacuuming (PostgreSQL)
Object Storage (Blob Store)
Supported Backends: Local Disk:- Content addressing (SHA256)
- Automatic deduplication
- Optional compression (zstd)
- Encryption at rest
- Multi-region replication
Cache Layers
Multi-tier caching for performance: 1. In-Memory Cache:- LRU eviction
- Hot data (ActionResults, small blobs)
- Typical size: 1-10 GB
- Fastest access (microseconds)
- Recently accessed blobs
- Typical size: 50-500 GB
- Fast access (milliseconds)
- Reduces cloud storage API calls
- Long-term persistence
- Unlimited size
- Higher latency (10-100ms)
- Most cost-effective for large datasets
Data Lifecycle
Ingestion Flow
-
Build Event Ingestion:
- Bazel streams build events to BuildBuddy
- Events parsed and validated
- Metadata extracted and stored in database
- File references noted for later retrieval
-
Artifact Upload:
- Bazel uploads build outputs to CAS
- Digests computed (SHA256)
- Blobs written to object storage
- Stored in multiple cache tiers
-
Action Cache Update:
- After successful action execution
- ActionResult mapped to action digest
- Stored for future cache hits
Retention and TTL
Database Retention:- Background job runs periodically
- Identifies expired data based on TTL
- Deletes expired database records
- Removes unreferenced blobs from storage
- Updates usage metrics
Backup and Recovery
Database Backups:- Daily full backups
- Continuous transaction log archival
- Point-in-time recovery capability
- Tested restore procedures
- Built-in durability (11 9’s for S3/GCS)
- Cross-region replication
- Versioning for critical data
- Lifecycle policies for archival
Data Access Patterns
Write Patterns
-
High-volume writes during builds:
- Batched database inserts
- Parallel blob uploads
- Write-through caching
-
Action cache updates:
- Frequent small writes
- Overwrite existing entries
- Fast commit required
Read Patterns
-
UI page loads:
- Query invocation metadata
- Load associated targets/actions
- Lazy-load logs and artifacts
-
Cache reads during builds:
- High QPS for ActionResults
- Large blob downloads from CAS
- Concurrent reads from many clients
-
API queries:
- Filter by commit SHA, branch
- Paginated result sets
- Aggregations and analytics
Scalability
Database Scaling
Vertical Scaling:- Increase CPU, memory, IOPS
- Sufficient for most deployments
- Read replicas for query distribution
- Sharding by organization or date
- Connection pooling
Storage Scaling
Horizontal Scaling:- Cloud object storage scales automatically
- Add more disk nodes for local storage
- CDN for geographically distributed access
- Storage tiering (hot/warm/cold)
- Compression for large objects
- Deduplication reduces storage
- Lifecycle policies move to cheaper storage
Monitoring and Metrics
Database Metrics
- Query latency (p50, p95, p99)
- Connection pool utilization
- Slow query log analysis
- Table sizes and growth rate
- Replication lag (if using replicas)
Storage Metrics
- Total storage used (by type)
- Storage growth rate
- Cache hit rates (by tier)
- Blob access frequency
- Storage backend errors
- Deduplication savings
Data Quality Metrics
- Orphaned blobs (no references)
- Missing blobs (referenced but not found)
- Data corruption events
- Backup success rate