MongoDB vs. Apache Cassandra - Who Wins? | Systems Design Interview 0 to 1 with Ex-Google SWE

preview_player
Показать описание
Cassandra is probably the closest thing I have to a girlfriend at this point (well maybe the second closest)
Рекомендации по теме
Комментарии
Автор

Adding some more clarity here:

Q. we say that in cassandra all reads and writes go to one partition and we have very little support for distributed transactions; but at the same time cassandra uses quorum of nodes for read; is this because by all reads and writes going to one partition - we mean that they go to a single node after partition ? how does it make sense to use quorum of nodes to read then ?

ChatGPT said:
ChatGPT
You’re right in noting that Apache Cassandra operates differently compared to traditional databases, especially regarding how it handles reads, writes, and consistency. Let me clarify how Cassandra’s architecture handles these operations and why quorum-based reads still make sense.

Data Distribution and Partitioning
Partitioning: In Cassandra, data is distributed across nodes using a partitioning scheme. Each piece of data is assigned to a partition based on its partition key. This partition key determines which node (or nodes) will store that data.

Single Node Writes: When a write is performed, it is directed to a node responsible for that partition. This node is referred to as the "coordinator node." The coordinator node then writes the data to multiple replicas according to the replication factor. For example, if the replication factor is 3, the data is written to three different nodes.

Single Node Reads: Reads are a bit more complex. The coordinator node handles the read request. Depending on the consistency level specified for the read operation, the coordinator node will contact a certain number of replicas to retrieve the data. This is where the quorum concept comes into play.

Quorum Reads and Writes
Quorum: A quorum is a majority of nodes in a given set. For example, in a replication factor of 3, a quorum would be 2 (since 3/2 = 1.5, rounded up to the nearest whole number).

Consistency Levels:

QUORUM Read: When a read request uses the QUORUM consistency level, the coordinator node will read the data from a quorum of replica nodes. This ensures that the data retrieved is consistent and up-to-date, as a majority of the replicas agree on the value.

QUORUM Write: Similarly, for writes, if the QUORUM consistency level is specified, the write operation must be acknowledged by a quorum of replica nodes before it is considered successful. This helps ensure that the write is durable and consistent.

How It All Fits Together
Coordinator Role: The coordinator node plays a central role in both reads and writes. It handles the routing of the request and gathers responses from the appropriate replica nodes.

Quorum-Based Reads: Even though all writes and reads for a partition go through a single coordinator node, the actual data is distributed across multiple replicas. By using a quorum of nodes for reads, Cassandra ensures that the data retrieved is consistent with the most recent write. The coordinator node verifies the data with a majority of replicas to ensure accuracy.

Consistency vs. Availability: Cassandra prioritizes availability and partition tolerance (according to the CAP theorem), and consistency is tunable based on the consistency level. By using quorum-based approaches, Cassandra balances between strong consistency and high availability.

In summary, while reads and writes are directed to specific partitions, the use of quorum levels for reads and writes involves multiple nodes to ensure data consistency and fault tolerance. The coordinator node handles the routing but relies on a majority of nodes to validate the read or write operations, thus maintaining consistency across the distributed system.



So; strong consistency is made configurable by just reading from the coordinator node (in this case the size of the quorum is 1 - the coordinator node itself); but cassandra is configurable for leaderless replication; at the same time it's not happy with cross-partition transactions (2PC); as in all the relevant data for a partition should be kept in that partition itself.

LegitGamer
Автор

We thank you for having no life and making these videos 🙂. Loved this one too.

geekwithabs
Автор

Cassandra's data integrity can be made better by configuring quorums.
However, due to hinted handoff-> it still cannot provide any transactional/strong consistency guarantees

niranjhankantharaj
Автор

@2:20 Your information is wrong there. I think you wanted to say that there are Partition keys (at least one) and Cluster keys (0 or more). Together they form the Primary key. Please review the video as it is misinforming thousands of people.

sergiuchiuchiu
Автор

@7:36 you mentioned btree databases write it to disk first. However with WAL in combination of btress, do DBs still writes go to disk ? I was under impression that with WAL they first write to WAL and then asynchronously they flush from memory to btress on disk. Please correct me if i am wrong.

Summer-qsrq
Автор

You mention that btree writes do originally go to disk. That's wrong. PostgreSQL writes go to btree index pages which reside in memory.

BlindVirtuoso
Автор

Why do the nodes share the hash ring configuration via a gossip protocol instead of using something like ZooKeeper? Is there some kind of benefit to using a Gossip protocol instead? Or am I misunderstanding this.

javaadpatel
Автор

Is there any downside of MongoDB's ACID guarantees on de-normalized data, i.e. are writes slower than MySQL? It seems almost too good to be true, esp. say if a write has many duplicated locations it needs to transactionally update

Also I knowCassandra's commonly used for chat applications as you mentioned, but I'm having trouble understanding why it's strictly preferential to say a document store. Say you had cluster key = chatID, sortKey = timeStamp, and one more column chatMessage = message contents. Yes the chatMessages have good locality, but many of COS other benefits (encoding compression, dictionary compression) aren't really relevant on content as variable as chat messages

JLJConglomeration
Автор

Nice video.
I have a question. I read somewhere that "While transactions in MongoDB can span multiple documents within a shard, they cannot span multiple shards within a sharded cluster.". This limits us in comparing this to traditional SQL isn't it ?

rakeshvarma
Автор

4:07 When you say on Cassandra all reads and writes should go to ONE partition. Does that mean after a consistent hash, a partition on one node? But I thought read is from a quorum? I guess I'm thinking one partition means a partition on a single node. That's not what a partition means?

sourcerer
Автор

Hey Jordan, let's say we have 5 partitions of Cassandra each storing some data. Is there a way to find out the oldest entry from those partitions, considering there are multiple keys for partition(like senderid, receiver I'd)

AnilYadav-xgiw
Автор

0:56 "you would use a single leader replication but that would just be sharded to get higher write throughput" I thought being single leader means writing to the leader node only and sharding helps with read throughput?

sourcerer
Автор

Can you please explain at 3:06, how are Gossip protocol and Consistent Hashing connected? I understand that in gossip protocol basically we designate the start note and we propagate state updates to the rest of the nodes, but how does consistent hashing come into play?

bokistotel
Автор

Cassandra only used for chat application? or is there any other benefits? Because if read throughput is poor, then historical chat data retrieval would take a hit on overall latency isn't it ?

arteigen
Автор

Amazing summary.
1. Can you do a similar video on dynamo db and compare it to Cassandra or other No sql db .

Separately what’s the notepad software you are using .

AchintoBanerjee
Автор

If Mongodb is providing facilities as MySQL, then why everyone is not using it?

kushalsheth
Автор

Unrelated to the video, but I'm surprised that you're still able to consistently make content for youtube. Figured you would actually have no life with the new job.

raymondyang
Автор

Cluster key and sort key are the same thing. You meant to say partition key and clustering key.

paulfunigga