Complete the code to identify the sharding key in a database shard.
shard_key = request.get('[1]')
The user_id is commonly used as a sharding key to distribute data evenly across shards.
Complete the code to calculate the shard number using modulo sharding.
shard_number = hash(user_id) [1] total_shardsThe modulo operator % is used to map the hash value to a shard number within the total shards.
Fix the error in the shard lookup function to correctly route requests.
def get_shard(user_id): shard_id = hash(user_id) [1] num_shards return shards[shard_id]
The modulo operator % ensures the shard_id is within the valid shard range.
Fill both blanks to implement range-based sharding for user IDs.
if user_id [1] 1000: shard = shards[[2]]
Users with IDs less than 1000 go to shard 0.
Fill all three blanks to create a dictionary comprehension for consistent hashing buckets.
buckets = [1]: hash([2]) [3] num_buckets for [2] in nodes}
The comprehension maps each node to a bucket using modulo of its hash.
