ysql
YugabyteDB YSQL Best Practices
This skill includes:
references/smart-drivers.md— connection examples for Python, Java, Go, Node.jsreferences/retry-patterns.md— transaction retry code in Python and Java
YugabyteDB is a distributed, PostgreSQL-compatible database (YSQL on port 5433) that is ACID-compliant, highly available, horizontally scalable, and supports hash/range sharding of tables and indexes. Every design choice should balance read efficiency, write scalability, and operational cost.
Connection URI example: postgresql://yugabyte:yugabyte@localhost:5433/yugabyte
Important: one connection endpoint by itself does not guarantee load balancing. Use driver-native topology/load-balance features where available, and combine with infrastructure load balancing (for example CSP/Kubernetes/Istio) when needed.
Schema Design
Primary Key Strategy
Prefer natural primary keys when they are stable and well distributed. Surrogate keys are often useful for legacy integration and interoperability, but they are not automatically the best primary lookup shape for distributed systems.
Avoid monotonically increasing leading key values for range-sharded access paths (sequences, timestamps, UUIDv7, lexicographically increasing text IDs).