Date: Wed, 18 Dec 2019 17:05:08 GMT
<p>Database Sharding Crash Course (with Postgres examples)</p> <p>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.</p> <p>What is sharding?</p> <p>sharing key / partition key</p> <p>Consistent Hashing</p> <p>Horizontal partitioning vs Sharding</p> <p>Example</p> <p>Pros and cons</p> <p>What is Sharding? 1:30</p> <p>Consistent Hashing 4:50</p> <p>Horizontal partitioning vs Sharding 7:36</p> <p>Example 8:45</p> <p>Spin up Docker Postgres Shards 10:02</p> <p>Write to the shard 17:25</p> <p>Read from the Shard 39:20</p> <p>Pros & Cons 51:10</p> <p>Cards</p> <p>Postgres pgadmin Docker 8:54</p> <p>Postgres Javascript 18:18</p> <p>URL vs Query param 22:30</p> <p>CORS 29:30</p> <p>sql injection 42:40</p> <p>Source Code</p> <p><a href="https://github.com/hnasr/javascript_playground/tree/master/sharding">https://github.com/hnasr/javascript_playground/tree/master/sharding</a></p> <p>Docker commands (including pgadmin)</p> <p><a href="https://github.com/hnasr/javascript_playground/blob/master/sharding/shards/commands.txt">https://github.com/hnasr/javascript_playground/blob/master/sharding/shards/commands.txt</a></p> <p>Dockerfile & init.sql</p> <p><a href="https://github.com/hnasr/javascript_playground/tree/master/sharding/shards">https://github.com/hnasr/javascript_playground/tree/master/sharding/shards</a></p> <p>Horizontal partitioning vs Sharding</p> <p>HP same database instance so you can still join</p> <p>sharding across instances (different server)</p> <p>Pros</p> <p>Extreme scale rdbms</p> <p>Optimal and Smaller index size</p> <p>Cons</p> <p>Transactions across shards problem</p> <p>Rollbacks</p> <p>Schema changes</p> <p>Complex client (aware of the shard)</p> <p>Joins</p> <p>Has to be something you know in the query</p> <p>Example</p> <p>URL shortener</p> <p>create table</p> <p>CREATE TABLE public.test1</p> <p>(</p> <p>id serial NOT NULL primary key,</p> <p>url text,</p> <p>url_id character(5)</p> <p>)</p> <p>Spin up 3 instances</p> <p>p1</p> <p>P2</p> <p>P3</p> <p>post</p> <p>get</p>