Menu

Post image 1
Post image 2
1 / 2
0

Database Sharding Strategies for Growing Video Platforms

DEV Community·ahmet gedik·23 days ago
#7XtS2jTQ
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.

Read More