In Mongo what is the difference between sharding and replication?

后端 未结 8 1675
渐次进展
渐次进展 2020-12-12 14:43

Replication seems to be a lot simpler than sharding, unless I am missing the benefits of what sharding is actually trying to achieve. Don\'t they both provide horizontal sca

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 15:16

    Just to put this somewhere...

    The most basic way to run mongo is as standalone server.

    • You write a config (file or cli options)
    • initiate the server using mongod

    For this picture, I didn't include the "client". Check the next one.

    • A replica set is a set of servers initialized exactly as above with a different config file.
    • To link them, we connect to one of them, and initialize the replica set mode.
    • They will mirror each other (in the most common configuration). This system guarantees high availability of data.

    The initialization of the replica set is represented in the red border box.

    • Sharding is not about replicating data, but about fragmenting data.
    • Each fragment of data is called chunk and goes to a different shard. shard = each replica set.
    • "main" server, running mongos instead of mongod. This is a router for queries from the client.

    Obvious: The trade-off is a more complex architecture. Novelty: configuration server (again, a different config file).

    There is much more to add, but apart from the words the pictures hold much the same.


    Even mongoDB recommends to study your case carefully before going sharding. Vertical scaling (vs) is probably a good idea at least once before horizontal scaling (hs).

    vs is done upgrading hardware (cpu, ram, etc). hs is needs more computers (but could be cheap computers).

提交回复
热议问题