-
Notifications
You must be signed in to change notification settings - Fork 0
Notes
Xiahua Liu edited this page Jul 5, 2025
·
3 revisions
This guide provides essential considerations and best practices for application developers using PawnDB in their systems.
PawnDB does not support automatic operation coalescing or merging within the same transaction. Each operation is treated independently and stored separately in the rollback table.
What this means:
- Deleting a record created in the same transaction results in two separate operations
- Updating a record multiple times creates multiple rollback entries
- The rollback table stores all operations, not just the net effect
Best Practices:
- Avoid "undoing" operations within the same transaction
- Design transactions to perform write operations (Insert, Update, Delete) as final actions
- While not forbidden, counter-effect actions are inefficient and should be minimized
Example of inefficient patterns:
// Inefficient - creates unnecessary rollback entries
INSERT record A
UPDATE record A
DELETE record A
PawnDB follows an optimistic transaction model with asymmetric costs:
Commit Operations:
- ✅ Inexpensive - Minimal overhead for successful transactions
- ✅ Fast - Optimized for the common success case
Rollback Operations:
⚠️ Costly - Requires executing all rollback steps in reverse order⚠️ Time-consuming - Proportional to the number of operations performed
Recommendations:
- Design applications to minimize transaction aborts
- Use abort operations judiciously and only when necessary
- Consider breaking large transactions into smaller, more likely-to-succeed units
Proper table sizing is crucial for optimal PawnDB performance and preventing transaction bottlenecks.
Key Considerations:
- Record capacity - Ensure tables can accommodate expected record volumes
- Insertion patterns - Size tables to handle peak insertion rates
- Concurrent access - Account for multiple transactions accessing the same table
Performance Impact:
- Undersized tables can cause transactions to wait during record insertion
- Waiting transactions significantly reduce overall system throughput
- Blocked operations can cascade and affect other transactions
Sizing Recommendations:
- Monitor table utilization and growth patterns
- Size tables with sufficient headroom for peak loads
- Consider implementing table expansion mechanisms for dynamic workloads
- Keep transactions focused - Limit scope to related operations
- Minimize transaction lifetime - Reduce lock contention
- Plan for failure - Design with rollback costs in mind
- Batch similar operations - Group related changes when possible
- Expect timeouts - Handle lock acquisition failures gracefully
- Implement retry logic - Use exponential backoff for transient failures
- Monitor rollback frequency - High rollback rates indicate design issues
- Log transaction patterns - Track performance and failure modes
- Track transaction success rates - Monitor commit vs. rollback ratios
- Measure operation latency - Identify slow operations
- Monitor table utilization - Ensure adequate capacity
- Watch for lock contention - Identify hotspot tables or records
- Repeated undoing operations - Creates unnecessary rollback overhead
- Oversized transactions - Increases rollback costs and lock contention
- Inadequate table sizing - Causes insertion bottlenecks
- Ignoring rollback costs - Leads to poor performance under failure conditions
- High rollback-to-commit ratios
- Frequent transaction timeouts
- Degraded performance under load
- Excessive lock wait times