designing-application-transactions

Designs CockroachDB transaction patterns including retry handling and locking.

3|3|Updated Mar 11, 2026
One-click install
npx skills add https://github.com/cockroachdb/claude-plugin --skill designing-application-transactions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: designing-application-transactions
Source: https://github.com/cockroachdb/claude-plugin/tree/main/skills/application-development/designing-application-transactions
Command: npx skills add https://github.com/cockroachdb/claude-plugin --skill designing-application-transactions

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guides application developers in designing correct, performant transaction patterns for CockroachDB, covering transaction lifetime, implicit vs explicit transactions, retry handling with exponential backoff, pushing invariants into SQL, selective pessimistic locking, set-based operations, connection pooling, prepared statements, keyset pagination, follower reads, and separating business logic from database logic. Use when building applications on CockroachDB, designing transaction workflows, handling retries, optimizing application-layer database interactions, or configuring connection pools.

Core Features & Use Cases

  • Designing transaction patterns to ensure correctness and resilience under serialization failures.
  • Deciding between implicit autocommit and explicit transactions, with guidance on when to use each.
  • Implementing retry backoff strategies and idempotent operations to safely handle contention.
  • Applying set-based SQL patterns, proper locking, and avoiding read-modify-write loops.
  • Guidance on integrating transaction design with application architecture, including connection pooling and separation of concerns.

Quick Start

Review your current transaction flows and implement short-lived transactions, guarded updates, and proper retry logic per CockroachDB best practices.

Frequently Asked Questions about designing-application-transactions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle transaction retries in CockroachDB?

Handle CockroachDB transaction retries by implementing explicit retry loops with exponential backoff. Applications catch serialization failures and re-execute the entire transaction block, ensuring idempotent operations to safely manage contention without corrupting state.

When should I use explicit vs implicit transactions in CockroachDB?

Use explicit transactions in CockroachDB when multiple statements must commit atomically, ensuring ACID guarantees. Use implicit autocommit transactions for single statements to prioritize performance and reduce lock contention overhead.

What's the best way to avoid read-modify-write loops in CockroachDB?

Avoid read-modify-write loops in CockroachDB by pushing invariants into SQL and using set-based operations. This pattern reduces round trips, leverages database-side computation, and minimizes contention by applying updates directly via guarded statements.

How do I configure safe connection pooling for CockroachDB transactions?

Configure safe connection pooling for CockroachDB by maintaining short-lived transactions and utilizing prepared statements. This design pattern optimizes application-layer database interactions, prevents connection leaks, and ensures efficient resource utilization under high concurrency.

Why does my CockroachDB transaction fail under high concurrency?

CockroachDB transactions fail under high concurrency due to serialization conflicts during contention. Resolve this by implementing proper retry handling with exponential backoff, applying selective pessimistic locking, and ensuring operations remain idempotent.

Can I use follower reads to optimize CockroachDB transaction performance?

Yes, you can use follower reads to optimize CockroachDB transaction performance by allowing read operations to hit geographically closer replicas. This pattern significantly reduces read latency for historical data while maintaining strict consistency for write operations.