๐Ÿ—„๏ธ Databases

YugabyteDB

A PostgreSQL-compatible distributed SQL database

๐Ÿ“– Detailed Explanation

YugabyteDB is an open-source distributed SQL database compatible with PostgreSQL. Designed with inspiration from Google Spanner, it provides horizontal scaling and high availability while maintaining ACID transactions.

Key features include PostgreSQL compatibility (easy migration of existing apps), automatic sharding, distributed transactions (strong consistency without 2PC), multi-region deployment, and automatic rebalancing. It also supports a Cassandra-compatible API (YCQL).

It is suitable when you want to move existing PostgreSQL/MySQL applications to a distributed environment with minimal code changes.

๐Ÿ’ป Code Example

# YugabyteDB ํด๋Ÿฌ์Šคํ„ฐ ์‹œ์ž‘ (Docker)
docker run -d --name yugabyte \
  -p 5433:5433 -p 9000:9000 \
  yugabytedb/yugabyte:latest \
  bin/yugabyted start --daemon=false

# PostgreSQL ํด๋ผ์ด์–ธํŠธ๋กœ ์—ฐ๊ฒฐ
psql -h localhost -p 5433 -U yugabyte

-- ํ…Œ์ด๋ธ” ์ƒ์„ฑ (PostgreSQL ๋ฌธ๋ฒ• ๊ทธ๋Œ€๋กœ)
CREATE TABLE orders (
    id SERIAL PRIMARY KEY,
    user_id INT NOT NULL,
    total DECIMAL(10,2),
    created_at TIMESTAMP DEFAULT NOW()
) SPLIT INTO 3 TABLETS;  -- ์ƒค๋”ฉ ์„ค์ •

-- Python์—์„œ ์‚ฌ์šฉ (psycopg2 ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ)
import psycopg2

conn = psycopg2.connect(
    host="localhost",
    port=5433,
    database="yugabyte",
    user="yugabyte"
)

cursor = conn.cursor()
# ๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜ ์ž๋™ ์ง€์›
cursor.execute("BEGIN")
cursor.execute("INSERT INTO orders (user_id, total) VALUES (%s, %s)", (1, 99.99))
cursor.execute("UPDATE users SET order_count = order_count + 1 WHERE id = %s", (1,))
conn.commit()

๐Ÿ—ฃ๏ธ Examples of Practical Conversations

Architect: "We need to expand a global service on PostgreSQL. What options are there?"

DBA: "I think YugabyteDB would be a good fit. Since it's PostgreSQL-compatible, we can use the existing code almost as is, and multi-region deployment can also reduce latency."

Architect: "How is it different from CockroachDB?"

DBA: "Both are distributed SQL, but YugabyteDB has higher PostgreSQL compatibility, and it's flexible because it also supports the Cassandra API. It also has more diverse performance tuning options."

Interviewer: "Do you have experience with distributed SQL databases?"

Candidate: "I have experience building a global service DB with YugabyteDB. I deployed it across three regionsโ€”Korea, the US, and Europeโ€”and achieved latency under 100ms for users in each region."

Interviewer: "How did you do the migration?"

Candidate: "Since it's PostgreSQL-compatible, I exported the schema with pg_dump and only added sharding settings per table using SPLIT INTO. For the application code, I only changed the connection string."

Take a mock interview on this topic โ†’ WIA SOOM AI Interview ยท Start for free

Reviewer: "The TABLET_SPLIT hint is missing from this query. Did you consider the data distribution?"

Developer: "Can't we just leave it with the default sharding?"

Reviewer: "It's fine at first, but if the user_id distribution is unbalanced, hotspots will form. It's better to explicitly set HASH sharding or RANGE sharding."

Developer: "Understood. I'll add a sharding strategy to the table design."

โš ๏ธ Cautions

๐Ÿ”— Related Terms

๐Ÿ“š Learn More