# YugabyteDB — Distributed SQL That Is Fully PostgreSQL Compatible > YugabyteDB is a distributed SQL database that reuses the PostgreSQL query layer while adding horizontal scale, multi-region replication, and resilience. It is Postgres you can shard across continents. ## Install Save as a script file and run: # YugabyteDB — Distributed PostgreSQL ## Quick Use ```bash # Single-node Docker quickstart docker run -d --name yb \ -p 7000:7000 -p 9000:9000 -p 5433:5433 -p 9042:9042 \ yugabytedb/yugabyte:latest bin/yugabyted start --daemon=false # Connect via psql (port 5433) — Postgres wire protocol psql -h localhost -p 5433 -U yugabyte ``` ```sql -- Exactly like Postgres CREATE TABLE orders ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id BIGINT NOT NULL, amount DECIMAL(18,2), created TIMESTAMPTZ DEFAULT now() ); INSERT INTO orders (user_id, amount) VALUES (1, 99.95), (2, 150.00); SELECT * FROM orders WHERE amount > 100; ``` ## Introduction YugabyteDB takes the PostgreSQL query layer — indexing, extensions, JSONB, stored procedures, triggers — and puts it on top of a distributed storage engine (DocDB, a fork of RocksDB). The result is a database that feels exactly like Postgres to your ORM, but scales horizontally and survives zone/region failures. With over 10,000 GitHub stars, YugabyteDB is used by General Motors, Kroger, Fidelity, and hundreds of companies that need Postgres semantics at cloud scale. It's a practical alternative to Spanner/Cosmos when you want PostgreSQL. ## What YugabyteDB Does YugabyteDB runs two APIs: **YSQL** (PostgreSQL wire protocol, 99% syntax compatible) and **YCQL** (Cassandra wire protocol for semi-structured). Data is sharded across nodes via consistent hashing and replicated via Raft. Distributed ACID transactions use the two-phase commit protocol with hybrid logical clocks. ## Architecture Overview ``` Clients -> YSQL (Postgres wire) or YCQL (Cassandra wire) | [Query Layer — reuses Postgres PG code] | [DocDB Storage Engine] Sharded tablets (Raft-replicated) Based on RocksDB + Raft + Hybrid Logical Clocks | +----+----+----+----+ | | | | | [Node A] [Node B] [Node C] ... (tablet peers) | [Coordinator master processes] Metadata, leader elections, load balancing ``` ## Self-Hosting & Configuration ```sql -- Geo-distributed table: user rows co-located with user's region CREATE TABLE user_profiles ( user_id BIGINT, region TEXT, data JSONB, PRIMARY KEY ((region), user_id) ) SPLIT INTO 3 TABLETS; -- Tablespaces for placement policies CREATE TABLESPACE us_east WITH ( replica_placement = '{"num_replicas": 3, "placement_blocks": [ {"cloud":"aws","region":"us-east-1","zone":"us-east-1a","min_num_replicas":1}, {"cloud":"aws","region":"us-east-1","zone":"us-east-1b","min_num_replicas":1}, {"cloud":"aws","region":"us-east-1","zone":"us-east-1c","min_num_replicas":1} ]}' ); ALTER TABLE user_profiles SET TABLESPACE us_east; ``` ## Key Features - **PostgreSQL compatible** — YSQL runs real Postgres query code - **Distributed transactions** — ACID across rows, tablets, regions - **Horizontal scale** — add nodes, tablets rebalance automatically - **Raft replication** — 3 or 5 replicas per tablet for HA - **Multi-region** — synchronous or asynchronous replication modes - **YCQL** — Cassandra wire protocol for key-value/wide-column use cases - **Postgres extensions** — PostGIS, pgvector, pg_cron, etc. supported - **YugabyteDB Aeon** — managed service on AWS/GCP/Azure ## Comparison with Similar Tools | Feature | YugabyteDB | CockroachDB | Spanner | Aurora / Cloud SQL | TiDB | |---|---|---|---|---|---| | SQL dialect | PostgreSQL | Postgres-like | Own | PostgreSQL / MySQL | MySQL | | Reuses PG code | Yes | No (own parser) | No | Yes (single region) | No | | Horizontal scale | Yes | Yes | Yes | Read replicas only | Yes | | Multi-region | Yes | Yes | Yes | Limited | Yes | | Extensions | Many PG exts | Limited | None | Many | Limited | | License | Apache-2.0 (core) | BUSL | Commercial (GCP) | Commercial | Apache-2.0 | | Best For | Postgres at scale | Postgres-like at scale | GCP-only teams | Managed Postgres | MySQL at scale | ## FAQ **Q: YugabyteDB vs CockroachDB?** A: Both aim for distributed SQL. Yugabyte reuses actual Postgres code for YSQL — the richest Postgres compatibility. Cockroach has Postgres-like syntax but a custom parser. For apps that rely on Postgres extensions (pgvector, PostGIS), Yugabyte wins. **Q: Can I just run Postgres with logical replication instead?** A: Yes, if you're OK with one primary + read replicas and asynchronous replication. Yugabyte gives you active-active writes across nodes/regions with ACID guarantees — a different scale/resilience tier. **Q: Is Yugabyte open source?** A: Yes, Apache-2.0 core. Some advanced management features (xCluster, security) are in the Enterprise/Aeon tiers. **Q: How is it for workloads with complex joins?** A: Joins across tablets incur network shuffles. Co-locate related rows (hash partition by customer_id) to keep joins fast. Yugabyte's planner handles distributed joins, but design matters for multi-region deployments. ## Sources - GitHub: https://github.com/yugabyte/yugabyte-db - Docs: https://docs.yugabyte.com - Company: Yugabyte - License: Apache-2.0 --- Source: https://tokrepo.com/en/workflows/09a16401-37d2-11f1-9bc6-00163e2b0d79 Author: Script Depot