When Do You Actually Need Sharding?
Most video platforms reach 10 million rows before sharding becomes necessary. Until then, proper indexing and query optimization outperform any sharding strategy. That said, understanding sharding early helps you design schemas that are shardable when the time comes.
TopVideoHub serves 9 Asia-Pacific regions. The natural partition keys — region and fetched_at — emerge directly from the data shape.
Strategy 1: PostgreSQL Native Partitioning
Declarative partitioning splits one logical table into physical child tables with zero application changes.
CREATE TABLE videos ( id BIGSERIAL , video_id TEXT NOT NULL , title TEXT NOT NULL , region TEXT NOT NULL , category_id INT , view_count BIGINT DEFAULT 0 , fetched_at TIMESTAMPTZ DEFAULT NOW (), PRIMARY KEY ( id , region ) ) PARTITION BY LIST ( region );
CREATE TABLE videos_jp PARTITION OF videos FOR VALUES IN ( 'JP' ); CREATE TABLE videos_kr PARTITION OF videos FOR VALUES IN ( 'KR' ); CREATE TABLE videos_tw PARTITION OF…