š„š²š½š¹š¶š°š®šš¶š¼š» š®š»š± š¦šµš®šæš¶š»š“ š¶š» šš®šš®šÆš®šš²š ā šŖšµš²š» š®š»š± šŖšµš?
ššš£šš”šš£š š”š¤šššØ š¤š š§ššššØ šš£š š¬š§šš©ššØ š¤š£ š šØšš£šš”š ššš©ššššØš ššš£ šššš¤š¢š š¤š«šš§š¬ššš”š¢šš£š. šš¤ š¢šš£ššš š©šššØ, š¬š šš§ššš©š šš¤š„šššØ š¤š š¤šŖš§ ššš©ššššØš š©š¤ ššš£šš”š š¢š¤š§š š§šš¦šŖššØš©šØ šØšš¢šŖš”š©šš£šš¤šŖšØš”š®. ššššØ šš¤š£ššš„š© š¢š¤šØš©š”š® šš„š„š”šššØ š©š¤ šš¤ššš ššš©ššššØššØ.
šš²š®š±š²šæ-šš¼š¹š¹š¼šš²šæ š š²š°šµš®š»š¶ššŗ (š š®ššš²šæ-š¦š¹š®šš²)
⢠One leader handles all ššæš¶šš²š. ⢠Followers are copies of the leader and handle reads. ⢠Followers may not always be fully up-to-date; this is called š²šš²š»ššš®š¹ š°š¼š»šš¶ššš²š»š°š. ⢠Data syncing from leader to followers is called šæš²š½š¹š¶š°š®šš¶š¼š», which can be ššš»š°šµšæš¼š»š¼šš or š®ššš»š°šµšæš¼š»š¼šš. ⢠In synchronous replication, writes are slower because the leader waits for followers to update before completing the write. ⢠Reads are usually routed to followers to reduce latency and spread load. ⢠If the leader fails, a follower can be promoted to leader.
šš²š®š±š²šæ-šš²š®š±š²šæ š„š²š½š¹š¶š°š®šš¶š¼š» (š šš¹šš¶-šš²š®š±š²šæ)
ā¢ ššŖš”š©šš„š”š š£š¤šššØ ššš© ššØ š”ššššš§šØ, each handling both reads and writes independently. ⢠This allows scaling write capacity by distributing writes across leaders. ⢠Because nodes sync asynchronously, the system may have lower immediate consistency (šš”šØš¤ š š£š¤š¬š£ ššØ š”š¤š¤šØšš”š® šš¤š£šØššØš©šš£t). ⢠Conflicts can arise if two leaders make conflicting writes, needing conflict resolution. ⢠Works well for distributed systems with users across regions, offering high availability and fault tolerance. ⢠Compared to synchronous replication, it offers lower latency but weaker consistency.
š¦šµš®šæš±š¶š»š“ ⢠Splits a large database into smaller parts called shards to handle huge datasets. ⢠Data is partitioned based on a key, which can be:
- Range-based (e.g., A-L, M-Z)
- Hash-based (data distributed by a hash function)
- NoSQL databases often have built-in sharding; SQL databases usually require manual sharding.
- Manual sharding in SQL databases can compromise ACID guarantees making transactions less reliable.
ššÆš„š¦š³š“šµš¢šÆš„šŖšÆšØ šµš©š¦š“š¦ š¤š°šÆš¤š¦š±šµš“ š©š¦šš±š“ šµš° š„š¦š“šŖšØšÆ š„šŖš“šµš³šŖš£š¶šµš¦š„ š„š¢šµš¢š£š¢š“š¦ š“šŗš“šµš¦š®š“ šµš©š¢šµ š£š¢šš¢šÆš¤š¦ š±š¦š³š§š°š³š®š¢šÆš¤š¦, š³š¦ššŖš¢š£šŖššŖšµšŗ, š¢šÆš„ š„š¢šµš¢ š¤š°šÆš“šŖš“šµš¦šÆš¤šŗ š¢š¤š¤š°š³š„šŖšÆšØ šµš° š“š±š¦š¤šŖš§šŖš¤ š¢š±š±ššŖš¤š¢šµšŖš°šÆ šÆš¦š¦š„š“.