Building Reliable, Scalable Applications with Erlang/OTP and the Ecosystem
Introduction
- The Promise of This Book
- What Makes the BEAM Different
- The Reference Application: Nexus
- How to Read This Book
- Prerequisites and Tooling
- A Note on Guarantees
Chapter 1: The BEAM Execution Model
- Virtual Machine Architecture and Schedulers
- Lightweight Processes: Creation, Cost, and Lifecycle
- Mailboxes and Message Passing Semantics
- Immutability and Concurrency Safety
- Garbage Collection: Generational, Concurrent, and Stop-the-World
- Process Isolation as the Foundation of Fault Tolerance
- Summary
Chapter 2: OTP Design Principles and Core Behaviours
- The OTP Philosophy: Let It Crash and Why It Works
- GenServer: Stateful Processes with Structured Interfaces
- Supervisors: Trees, Strategies, and Recovery Semantics
- Applications as Composable Units of Deployment
- Task Behaviours: OneShot, Sync, and Async Patterns
- Designing Process Hierarchies for a Real Application
- Summary
Chapter 3: Building the Reference Application — Architecture Foundations
- Requirements: Throughput, Latency, Availability, Consistency Goals
- Domain Decomposition: Services, Bounded Contexts, Process Ownership
- Supervision Topology Design for the Order System
- Message Protocol Design: Requests, Responses, Events, Timeouts
- State Ownership and Data Flow Architecture
- Initial Implementation: Local Single-Node Version
- Summary
Chapter 4: BEAM Distribution Fundamentals
- Nodes and Naming: Short Names, Long Names, and DNS
- The Distribution Protocol: epmd, Handshake, and Connection Management
- Cookies, Authentication, and Node Security
- Remote Process Calls and Distributed Registries
- Links and Monitors Across Nodes
- When BEAM Distribution Is (and Isn’t) the Right Tool
- Summary
Chapter 5: Clustering and Service Discovery
- Static vs Dynamic Clusters: Trade-offs and Use Cases
- libcluster Strategies: DNS, Kubernetes, Consul, Etcd Integration
- Horde: Distributed ETS, Registry, and Application Controller
- Running BEAM on Kubernetes: Pods, Services, and Node Discovery
- Cluster Membership Changes: Joins, Leaves, Partitions
- Security in Dynamic Clusters: TLS, mTLS, and Cookie Management
- Summary
Chapter 6: State Management, Replication, and Partitioning
- State Placement: In-Memory vs Persistent vs External Stores
- ETS and DETS: High-Performance Local Storage
- Mnesia: Distributed Database on BEAM — Capabilities and Limits
- Replication Strategies: Primary-Backup, Multi-Master, Quorum-Based
- Partitioning and Sharding: Keys, Ranges, and Hot Spots
- Choosing Between BEAM-Native and External Databases
- Summary
Chapter 7: Consistency Models and Distributed Transactions
- The CAP Theorem in Practice: What It Actually Means for Your System
- Consistency Models: Strong, Sequential, Causal, Eventual
- Distributed Transactions on BEAM: Mnesia DTC and Alternatives
- Saga Patterns and Compensating Actions for Long-Running Workflows
- Idempotency Design: Keys, Tokens, and Deduplication
- Retries, Timeouts, and Circuit Breakers in Concurrent Systems
- Summary
Chapter 8: Fault Detection, Recovery, and Network Partitions
- Failure Detection: Monitors, Heartbeats, and Timeouts
- Handling Node Crashes and Process Restarts in a Cluster
- Network Partitions: Detection, Diagnosis, and Recovery Strategies
- Split-Brain Prevention: Quorums, Leaders, and Tiebreakers
- Graceful Degradation: Read-Only Modes, Queuing, and Fallbacks
- Designing for Partial Outages: Dependency Failure Handling
- Summary
Chapter 9: Event-Driven Architectures and Message Flows
- Event Sourcing vs Event-Carried State Transfer: Choosing Wisely
- Pub/Sub on BEAM: :rpc, GenEvent, Phoenix PubSub, and Beyond
- Queues and Workers: Oban, Broadway, and Custom Implementations
- Backpressure and Flow Control: Preventing Overwhelm
- RabbitMQ and External Message Brokers in BEAM Systems
- Event Ordering Guarantees and Their Costs
- Summary
Chapter 10: Testing Distributed Systems
- Unit Testing OTP Behaviours: Isolating Processes and Time
- Integration Testing Across Nodes: Spin-Up, Teardown, Cleanup
- Simulating Failures: Crashes, Delays, Partitions, and Slow Links
- Property-Based Testing for Concurrent and Distributed Code
- Chaos Engineering on BEAM: Tools and Practices
- Testing Idempotency, Retries, and Recovery Paths
- Summary
Chapter 11: Observability, Profiling, and Performance Tuning
- Structured Logging in Distributed BEAM Applications
- Metrics: Counters, Gauges, Histograms, and Cardinality
- Distributed Tracing with OpenTelemetry on BEAM
- Profiling: Scheduler Utilization, Reductions, and Hot Paths
- Memory Analysis: Mailbox Growth, Process Spawns, and Leaks
- GC Tuning and Performance Optimization Techniques
- Summary
Chapter 12: Deployment, Releases, and Operations
- Building Production Releases: Mix Release, Rebar3, and Docker
- Configuration Management: Environments, Overrides, and Hot Reloading
- Secrets Management: Vault, KMS, and Runtime Injection
- TLS Termination and Node-to-Node Encryption
- Rolling Upgrades and Zero-Downtime Deployments
- Backups, Disaster Recovery, and Multi-Region Strategies
- Summary
Chapter 13: BEAM in the Modern Ecosystem — Comparisons and Trade-offs
- BEAM vs Microservices: Monolithic Clusters vs Distributed Services
- BEAM vs Actor Systems: Akka, Orleans, and Other Frameworks
- BEAM in Kubernetes: Fit, Friction, and Best Practices
- When to Choose BEAM: Strengths, Weaknesses, and Honest Trade-offs
- Hybrid Architectures: BEAM as One Component of a Larger System
- Architecture Decision Checklist for Distributed Systems
- Summary