Leanpub Header

Skip to main content

Software Verification with TLA+ and Claude Code

A Practical Guide to Formal Methods, Model Checking and Building Correct Software

Software Verification with TLA+ and Claude Code
This book is 100% completeLast updated on 2026-11-16

Distributed systems are hard enough to build without having to guess whether they work. This book shows experienced software engineers how to use TLA+ and TLC to find bugs before they reach production, with practical examples and four real-world case studies. It also explores how Claude Code can become a valuable partner in the verification process without replacing engineering judgment.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
191
Pages
About

About

About the Book

Distributed systems are notoriously difficult to get right. Race conditions, network partitions, node failures and unexpected execution sequences can expose subtle bugs that conventional testing may never uncover. Formal Verification of Distributed Systems with TLA+, TLC and Claude Code shows experienced software engineers how to move beyond testing individual scenarios toward mathematically verifying system behavior. Combining the rigor of Leslie Lamport's TLA+ specification language, the exhaustive exploration capabilities of the TLC model checker and the practical assistance of Claude Code, this book presents an accessible, hands-on approach to finding and understanding bugs before they reach production. Through clear explanations, complete runnable specifications and realistic case studies covering replicated key-value stores, leader election, distributed locks and transaction processing, you will learn to specify system behavior, verify safety and liveness properties, interpret counterexamples and integrate formal methods into everyday engineering workflows. No graduate-level mathematics or prior experience with formal verification is required. Written for engineers who want practical techniques rather than theoretical abstractions, this book demonstrates how to make distributed systems more predictable, reliable, correct and how to use AI as a powerful verification partner without surrendering the engineering judgment that correctness demands.

Bundle

Bundles that include this book

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience spanning software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. His work focuses on understanding complex systems, uncovering security weaknesses and developing practical solutions that make technology more secure, reliable and effective.

Through Steve Publications, he collaborates with experienced researchers, engineers and industry experts to create practical, technically rigorous books on various topics not limited to self-improvement, software development, cybersecurity, cloud computing, DevOps, artificial intelligence and enterprise technologies. His mission is to make complex technical subjects accessible through clear explanations, real-world examples and hands-on exercises that help IT professionals, students and technology enthusiasts build valuable, practical skills.

Steve Publications embraces AI as a supporting tool for translation, proofreading and editorial refinement, not as a substitute for original research, technical expertise, or hands-on experience. Some contributors choose to publish under pseudonyms to protect their privacy or maintain professional boundaries.

Behind every book is a commitment to technical accuracy, practical relevance and continuous improvement. Our publications are written, reviewed and maintained by experienced professionals, with support from a private community of more than 420 engineers and researchers. Rather than prioritizing volume or mass-produced AI-generated content, we focus on delivering reliable, useful resources that readers can apply in real-world environments.

We also welcome experienced professionals who want to share their knowledge by writing or reviewing books, particularly in specialized and emerging technology fields. If you have expertise to contribute, we invite you to get in touch and explore opportunities to collaborate.

Our commitment is simple: To deliver books that respect our readers' time, support their professional growth and provide lasting practical value. If a book does not meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

A Practical Guide to Formal Methods, Model Checking and Building Correct Software

Preface

Part I: Foundations

Chapter 1: The Verification Imperative

  1. 1.1 The Special Difficulty of Distributed Systems
  2. 1.2 What Formal Verification Is and Is Not
  3. 1.3 The Cost of Incorrect Distributed Systems
  4. 1.4 Why TLA+?
  5. 1.5 The Role of Claude Code
  6. 1.6 What You Will Learn

Chapter 2: A Brief History of Formal Methods and Their Industrial Renaissance

  1. 2.1 From Mathematics to Software
  2. 2.2 The Industrial Adoption
  3. 2.3 The AWS Case Study in Detail
  4. 2.4 The Microsoft Azure Experience
  5. 2.5 Lessons for the Individual Engineer

Chapter 3: Mathematical Foundations

  1. 3.1 Set Theory
  2. 3.2 Propositional and Predicate Logic
  3. 3.3 State Machines
  4. 3.4 Concurrent State Machines
  5. 3.5 Invariants
  6. 3.6 Summary

Chapter 4: Safety and Liveness

  1. 4.1 The Fundamental Dichotomy
  2. 4.2 Safety Properties
  3. 4.3 Liveness Properties
  4. 4.4 Combining Safety and Liveness
  5. 4.5 The Role of Fairness
  6. 4.6 Practical Guidance

Chapter 5: Introduction to Temporal Logic

  1. 5.1 The Need for a Logic of Time
  2. 5.2 The Always Operator
  3. 5.3 The Eventually Operator
  4. 5.4 The Next-State Relation
  5. 5.5 Until
  6. 5.6 The Leads-To Operator
  7. 5.7 Temporal Logic in Practice

Part II: Mastering TLA+

Chapter 6: TLA+ Syntax and Semantics

  1. 6.1 The Structure of a TLA+ Module
  2. 6.2 Variables and State
  3. 6.3 Operators and Expressions
  4. 6.4 Actions and Stuttering
  5. 6.5 The Specification
  6. 6.6 The Standard Modules
  7. 6.7 Common Syntax Patterns
  8. 6.8 The Semantics of TLA+
  9. 6.9 Summary

Chapter 7: Writing Your First TLA+ Specification

  1. 7.1 A Simple Counter
  2. 7.2 Adding an Invariant
  3. 7.3 Introducing a Bug
  4. 7.4 A Concurrent Example
  5. 7.5 Running TLC
  6. 7.6 Interpreting TLC Output
  7. 7.7 Summary

Chapter 8: PlusCal: TLA+ for Programmers

  1. 8.1 Why PlusCal?
  2. 8.2 The Basic Structure of a PlusCal Algorithm
  3. 8.3 Variables and Assignments
  4. 8.4 Control Flow
  5. 8.5 Processes and Concurrency
  6. 8.6 Procedures and Macros
  7. 8.7 Fairness
  8. 8.8 The Translation
  9. 8.9 When to Use PlusCal vs. Raw TLA+
  10. 8.10 Summary

Chapter 9: Structuring Complex Specifications

  1. 9.1 The Challenge of Scale
  2. 9.2 Modules and EXTENDS
  3. 9.3 Constants and Model Values
  4. 9.4 The INSTANCE Operator
  5. 9.5 Parameterized Operators
  6. 9.6 Hierarchical Specifications
  7. 9.7 Abstraction and Refinement
  8. 9.8 Naming Conventions and Style
  9. 9.9 Summary

Chapter 10: Nondeterminism, Concurrency and State

  1. 10.1 Nondeterminism in TLA+
  2. 10.2 Modeling Concurrency
  3. 10.3 Atomicity and Granularity
  4. 10.4 Shared State and Data Races
  5. 10.5 Communication and Message Passing
  6. 10.6 The State Space Explosion Problem
  7. 10.7 Summary

Part III: Model Checking with TLC

Chapter 11: The TLC Model Checker

  1. 11.1 What TLC Is
  2. 11.2 How TLC Works
  3. 11.3 The Configuration File
  4. 11.4 Running TLC
  5. 11.5 TLC Output
  6. 11.6 Performance Considerations
  7. 11.7 Summary

Chapter 12: TLC Configuration and Execution

  1. 12.1 The Configuration File in Detail
  2. 12.2 Constant Assignment
  3. 12.3 Initial State and Next-State Relation
  4. 12.4 Invariants
  5. 12.5 Properties
  6. 12.6 Deadlock Checking
  7. 12.7 Symmetry Reduction
  8. 12.8 Views
  9. 12.9 Constraints
  10. 12.10 Running TLC with Different Configurations
  11. 12.11 Summary

Chapter 13: Interpreting Results

  1. 13.1 Understanding TLC Reports
  2. 13.2 Reading Counterexamples
  3. 13.3 Common Types of Errors
  4. 13.4 Debugging Strategies
  5. 13.5 Validating Counterexamples
  6. 13.6 Summary

Chapter 14: Scaling Model Checking

  1. 14.1 The State Space Explosion Problem
  2. 14.2 Symmetry Reduction
  3. 14.3 State-Space Pruning
  4. 14.4 Abstraction
  5. 14.5 Optimization Techniques
  6. 14.6 Incremental Verification
  7. 14.7 When Model Checking Is Not Enough
  8. 14.8 Summary

Part IV: Claude Code as Engineering Partner

Chapter 15: Setting Up Claude Code for Formal Verification

  1. 15.1 What Claude Code Is
  2. 15.2 Installation
  3. 15.3 Verifying the Installation
  4. 15.4 Setting Up a TLA+ Project
  5. 15.5 Installing TLA+ Tools
  6. 15.6 Configuring Claude Code for TLA+
  7. 15.7 Your First Claude Code Session
  8. 15.8 Best Practices for Using Claude Code
  9. 15.9 Summary

Chapter 16: CLAUDE.md and Project Configuration

  1. 16.1 The Role of CLAUDE.md
  2. 16.2 Structure of a CLAUDE.md File
  3. 16.3 Writing Effective Instructions
  4. 16.4 Managing Context
  5. 16.5 Iterating on CLAUDE.md
  6. 16.6 Summary

Chapter 17: The Spec-to-Verification Workflow

  1. 17.1 The Workflow Overview
  2. 17.2 Step 1: Describing the System
  3. 17.3 Step 2: Generating the Specification
  4. 17.4 Step 3: Configuring TLC
  5. 17.5 Step 4: Running TLC
  6. 17.6 Step 5: Interpreting Counterexamples
  7. 17.7 Step 6: Fixing the Specification
  8. 17.8 Step 7: Iterating
  9. 17.9 Automating the Workflow
  10. 17.10 Summary

Chapter 18: Human-in-the-Loop Verification

  1. 18.1 The Necessity of Human Judgment
  2. 18.2 The Risks of AI-Assisted Verification
  3. 18.3 Managing Hallucination
  4. 18.4 Managing Overconfidence
  5. 18.5 The Human’s Role in the Loop
  6. 18.6 Building a Culture of Verification
  7. 18.7 The Ethics of AI-Assisted Verification
  8. 18.8 Summary

Part V: Case Studies

Chapter 19: Case Study: A Replicated Key-Value Store

  1. 19.1 The Problem
  2. 19.2 System Boundaries and Assumptions
  3. 19.3 Deriving the Specification
  4. 19.4 The Complete Specification
  5. 19.5 TLC Configuration
  6. 19.6 Running TLC
  7. 19.7 Introducing a Bug
  8. 19.8 Analyzing the Counterexample
  9. 19.9 Fixing the Bug
  10. 19.10 Lessons Learned

Chapter 20: Case Study: Leader Election and Consensus Protocols

  1. 20.1 The Leader Election Problem
  2. 20.2 Specifying a Simple Election Protocol
  3. 20.3 The TLA+ Specification
  4. 20.4 Modeling Network Failures
  5. 20.5 Verifying Safety and Liveness
  6. 20.6 Lessons from Consensus
  7. 20.7 Lessons Learned

Chapter 21: Case Study: Distributed Locks and Resource Allocation

  1. 21.1 The Distributed Lock Problem
  2. 21.2 Specifying a Centralized Lock Manager
  3. 21.3 The TLA+ Specification
  4. 21.4 Verifying Mutual Exclusion
  5. 21.5 Verifying Progress
  6. 21.6 Performance Implications of Lock Design
  7. 21.7 Lessons Learned

Chapter 22: Case Study: Transaction Processing and Fault Tolerance

  1. 22.1 Transactional Guarantees in a Distributed Setting
  2. 22.2 Specifying Two-Phase Commit
  3. 22.3 The TLA+ Specification
  4. 22.4 Modeling Coordinator and Participant Failures
  5. 22.5 Verifying Atomicity and Consistency
  6. 22.6 Message Delivery Semantics
  7. 22.7 Lessons Learned

Part VI: Integration, Comparison and Beyond

Chapter 23: From Specification to Implementation: Refinement and Correspondence

  1. 23.1 The Gap Between Model and Code
  2. 23.2 Refinement Mappings
  3. 23.3 Implementation Assumptions
  4. 23.4 Testing as a Complement to Verification
  5. 23.5 Tracing a Model Through a Production Implementation
  6. 23.6 Summary

Chapter 24: Formal Verification in the Engineering Workflow and CI/CD

  1. 24.1 When to Use Formal Verification: A Decision Framework
  2. 24.2 Integrating TLC into CI/CD Pipelines
  3. 24.3 Specification as Living Documentation
  4. 24.4 Team Adoption: Training, Culture and Process
  5. 24.5 Measuring the Value of Verification
  6. 24.6 Summary

Chapter 25: The Verification Landscape: TLA+ Versus Alloy, SPIN, Theorem Provers and Testing

  1. 25.1 Alloy: Relational Logic and Bounded Model Checking
  2. 25.2 SPIN and Promela: Process-Oriented Verification
  3. 25.3 Temporal Logic Model Checkers: NuSMV and Beyond
  4. 25.4 Theorem Provers: Isabelle, Coq, Lean and the TLA+ Proof System
  5. 25.5 Property-Based Testing and Concurrency Testing
  6. 25.6 Choosing the Right Tool
  7. 25.7 Summary

Conclusion: The Path to Correct Software

The Future of AI-Assisted Formal Verification

Final Recommendations

References

Glossary

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub