Sharding is a technique where a database is split into smaller, manageable pieces to improve performance and scalability.
Sharding is necessary when the database outgrows the capacity of a single machine, query performance degrades, high availability is required, scaling up is not feasible, or for faster local access.
The main types of sharding include Key-Based (Hash) Sharding, Geo Sharding, Directory-Based (Lookup) Sharding, Range-Based Sharding, and Vertical Sharding.
Challenges of sharding include managing complexity, difficulty in rebalancing, expensive joins across shards, ensuring data consistency, and separate backup and recovery strategies for each shard.