Menu

1 / 2

Database Sharding Strategies for Growing Video Platforms

DEV Community·ahmet gedik·6 months ago
#7XtS2jTQ
#strategy#database#postgres#scaling#partition
Reading 0:00
15s threshold

Sharding Is Not Your First Problem

Most video platforms can serve millions of rows from a single PostgreSQL instance with proper indexing. Design your schema to be shardable from day one, but shard only when necessary.

TrendVidStream serves 8 regions — UAE, Finland, Czech Republic, Denmark, Belgium, UK, Switzerland, US. The natural partition keys are region and fetched_at .

Strategy 1: PostgreSQL List Partitioning by Region

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 (), embed_broken BOOLEAN DEFAULT FALSE , title_lang TEXT , PRIMARY KEY ( id , region ) ) PARTITION BY LIST ( region );

CREATE TABLE videos_ae PARTITION OF videos FOR VALUES IN ( 'AE' ); CREATE TABLE videos_fi PARTITION OF videos FOR VALUES IN ( 'FI' ); CREATE TABLE videos_cz PARTITION OF videos FOR VALUES IN ( 'CZ' ); CREATE TABLE videos_dk PARTITION OF videos FOR VALUES IN ( 'DK' ); CREATE TABLE…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.