The Backend Engineering Show with Hussein Nasser

Episode 116 - Database Sharding


Listen Later

Database Sharding Crash Course (with Postgres examples)

Database sharding is process of segmenting the data into partitions that are spread on multiple database instances to speed up queries and scale the system.

What is sharding?

sharing key / partition key

Consistent Hashing

Horizontal partitioning vs Sharding

Example

Pros and cons

What is Sharding? 1:30

Consistent Hashing 4:50

Horizontal partitioning vs Sharding 7:36

Example 8:45

Spin up Docker Postgres Shards 10:02

Write to the shard 17:25

Read from the Shard 39:20

Pros & Cons 51:10

Cards

Postgres pgadmin Docker 8:54

Postgres Javascript 18:18

URL vs Query param 22:30

CORS 29:30

sql injection 42:40

Source Code

https://github.com/hnasr/javascript_playground/tree/master/sharding

Docker commands (including pgadmin)

https://github.com/hnasr/javascript_playground/blob/master/sharding/shards/commands.txt

Dockerfile & init.sql

https://github.com/hnasr/javascript_playground/tree/master/sharding/shards

Horizontal partitioning vs Sharding

HP same database instance so you can still join

sharding across instances (different server)

Pros

Extreme scale rdbms

Optimal and Smaller index size

Cons

Transactions across shards problem

Rollbacks

Schema changes

Complex client (aware of the shard)

Joins

Has to be something you know in the query

Example

URL shortener

create table

CREATE TABLE public.test1

(

id serial NOT NULL primary key,

url text,

url_id character(5)

)

Spin up 3 instances

p1

P2

P3

post

get

...more
View all episodesView all episodes
Download on the App Store

The Backend Engineering Show with Hussein NasserBy Hussein Nasser

  • 4.9
  • 4.9
  • 4.9
  • 4.9
  • 4.9

4.9

40 ratings


More shows like The Backend Engineering Show with Hussein Nasser

View all
Freakonomics Radio by Freakonomics Radio + Stitcher

Freakonomics Radio

32,263 Listeners

Software Engineering Radio - the podcast for professional software developers by team@se-radio.net (SE-Radio Team)

Software Engineering Radio - the podcast for professional software developers

273 Listeners

Risky Business by Patrick Gray

Risky Business

373 Listeners

Science Vs by Spotify Studios

Science Vs

12,166 Listeners

Syntax - Tasty Web Development Treats by Wes Bos & Scott Tolinski - Full Stack JavaScript Web Developers

Syntax - Tasty Web Development Treats

990 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,110 Listeners

Practical AI by Practical AI LLC

Practical AI

212 Listeners

Within Reason by Alex J O'Connor

Within Reason

1,659 Listeners

All-In with Chamath, Jason, Sacks & Friedberg by All-In Podcast, LLC

All-In with Chamath, Jason, Sacks & Friedberg

10,231 Listeners

Dwarkesh Podcast by Dwarkesh Patel

Dwarkesh Podcast

548 Listeners

Big Technology Podcast by Alex Kantrowitz

Big Technology Podcast

514 Listeners

Hard Fork by The New York Times

Hard Fork

5,544 Listeners

The AI Daily Brief: Artificial Intelligence News and Analysis by Nathaniel Whittemore

The AI Daily Brief: Artificial Intelligence News and Analysis

659 Listeners

Prof G Markets by Vox Media Podcast Network

Prof G Markets

1,471 Listeners

The Pragmatic Engineer by Gergely Orosz

The Pragmatic Engineer

74 Listeners