Vitess
Vitess
MySQL horizontal scaling middleware. Developed at YouTube.
Vitess
MySQL horizontal scaling middleware. Developed at YouTube.
Vitess is a database clustering system that enables horizontal scaling of MySQL. It was developed to handle large-scale MySQL workloads at YouTube, and is currently a graduated project of the CNCF (Cloud Native Computing Foundation).
Vitess's core features include automatic sharding (sharding logic defined with VSchema), query routing (applications use a single endpoint), connection pooling, query rewriting (optimizing complex queries), and online schema changes.
It is used to run MySQL at petabyte scale in large-scale services such as Slack, Square, GitHub, and HubSpot. It is optimized for Kubernetes environments.
# Vitess VSchema μμ (μ€λ© μ€μ )
# νμΌ: vschema.json
{
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
}
},
"tables": {
"users": {
"column_vindexes": [
{
"column": "user_id",
"name": "hash"
}
]
},
"orders": {
"column_vindexes": [
{
"column": "user_id",
"name": "hash"
}
]
}
}
}
# vtgate μ°κ²° (MySQL νΈν νλ‘ν μ½)
mysql -h vtgate-host -P 15306 -u user -p
# μ ν리μΌμ΄μ
μμλ μΌλ° MySQL λλΌμ΄λ² μ¬μ©
import mysql.connector
conn = mysql.connector.connect(
host="vtgate-host",
port=15306,
user="app_user",
database="commerce"
)
# 쿼리λ Vitessκ° μλμΌλ‘ μ€λμ λΌμ°ν
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE user_id = 12345")
cursor.execute("SELECT * FROM orders WHERE user_id = 12345") # κ°μ μ€λ
CTO: "We can't scale up any further with a single MySQL instance. What options do we have?"
DBA: "If we adopt Vitess, we can shard while keeping the existing MySQL. And we can keep application code changes to a minimum."
CTO: "How is that different from sharding it ourselves?"
DBA: "If you declare the sharding logic with VSchema, Vitess automatically handles query routing, join processing, and rebalancing. The operational burden is greatly reduced."
Interviewer: "How did you implement MySQL sharding?"
Candidate: "I adopted Vitess and applied hash sharding based on user_id. I defined the sharding key with VSchema, and vtgate routes queries to the appropriate shards."
Interviewer: "How do you handle cross-shard queries?"
Candidate: "Vitess gathers results from multiple shards using a scatter-gather approach. However, for performance, I designed queries as single-shard queries whenever possible, and separated cross-shard queries into asynchronous processing."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "Looking at this query, there's no user_id in the WHERE clause, so it looks like it will scan all shards."
Developer: "Oh, I didn't include the sharding key in the lookup condition."
Reviewer: "In Vitess, queries without a sharding key are broadcast to all shards. Add a user_id condition if possible, or if that's unavoidable, put a cache layer in front."
Developer: "Understood. I'll review the API design again from the beginning."