⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠

Text Elements

pastebin.com

G

o

o

g

l

e

Application server

{

}

DocumentDB Shard 2

pastes

key: primary id paste_data: str title: str expiry?: datetime password?: hashed password salt?: str

How to create a hash?

  • We want a hash that uses letters and numbers.
  • This 26 + 26 + 10 = 62 unique chars.
  • 6 chars gives us ~10B possibilities.
  • Encode each incremented value in Base62 with length 6.

Example: pastebin.com/paste?id=aKfe2v

How do we deal with concurrent requests? We don’t want two pastes to use the same counter value.

  • We can have a coordination service that hands out exclusive “leases” to certain number ranges.
  • E.g. Server 1 can use [1,9999], Server 2 can use [10000, 19999].

Application server

Load Balancer

{

}

Document DB Shard 1

Sharding:

  1. We could shard by key.
  • All pastes with id starting with “a” would be created sequentially, leading to unbalanced loads.
  1. We could shard by paste origin IP address.
  • We might have to split it down further if one region is particularly busy.
  1. We could shard by consistent hashing.
  • Would have less hot spots than first option.

{

}

{

}

replicated for durability and high r/w ratio.

Distributed Coordination Service

manage range counters

manage db health

Key

Key

Value

Value

Cache

Very popular pastes can be cached to reduce database load.