#sharding #distributed-systems #location #user #algorithm #sized #right

location_based_sharding

Right sized sharding algorithm

5 releases

0.1.4 Feb 6, 2022
0.1.3 Feb 5, 2022
0.1.2 Jan 25, 2022
0.1.1 Jan 25, 2022
0.1.0 Jan 23, 2022

#1854 in Algorithms

MIT license

40KB
842 lines

Location Based Sharding Algorithm

Docs.rs

Based off Tinder own location based sharding algorithm, the algorithm will create shards based off of the "heat" of users in a particular location. This flexible sharding schema allows less dense locations to be encompassed in less shards and more densely populated areas to be split in to different shards.

Sharding metadata

When sharding is initiated, it creates shards based off the current user score. These shards need to be persisted in some sort of persistent store or database. This can be used for something like elastic search or location based sharding in any kind of database.

Some trade offs for consideration:

  • Users in dense cities may have to hit multiple shards
  • uses who live on edges may wander across and their information will have to moved across

Example

// This can also be serialized and pulled from Redis
// let geoshards = GeoshardBuilder::from(&json_string_from_ddb)).unwrap();
let geoshards = GeoshardBuilder::user_count_scorer(8, Box::new(vec![].into_iter()), 40, 100).build();
let shard_searcher = GeoShardSearcher::from(geoshards);
let shard_user_is_in = shard_searcher.get_shard_user(some_user);
// Query you index based off the shard ^^^

Dependencies

~2.7–4MB
~79K SLoC