Wonderful explanation of the CAP theory article

Source: Internet
Author: User
Tags call back

Turn from 360doc

Chapter 1: "Remembrance Inc" Your new venture:

Last night when your spouse appreciated to remembering her birthday and bringing she a gift, a strange idea strikes yo U. People is so bad in remembering things. And you ' re sooo good at it. So why isn't start a venture that would put your talent to use? The more your think about it and the more you like it. In fact you even come up with a news paper ad which explains your idea

Chapter One: Memory company

Last night when your wife thanked you for remembering her birthday and bought her a present, you suddenly came up with an idea. People's memory is always bad and you are so good at remembering, so why not use your talent to do a career? The more you think about it, the better the idea. In fact, you even came up with a news ad to explain your idea.

Remembrance inc! -Never forget, even without remembering!

Ever felt bad, so, forget so much? Don ' t worry. Help is just a phone away!

When you need to remember something, the just call 555--55-remem and the tell us about you need to remember. For eg., call us and let us know of your boss ' s phone number, and forget to remember it. When you need-know it back: Call back the same number[(555)--55-remem] and we'll tell you what ' s your boss's phone number.

Charges:only $0.1 per request

Memory Company! -no memory, never forget

Have you ever felt depressed about forgetting? Don't worry, just a phone call. When you need to remember something, call 555-55 and tell us what you want to remember. For example, call us to know your boss's phone number, and then forget about it. When you want to know what has been forgotten, dial the same number and we will tell you the phone number of the boss. Fee: $0.1 per request.

So, your typical phone conversation would look like this:

· Customer:hey, Can you store my neighbor ' s birthday?

· You:sure: When is it?

· customer:2nd of Jan

· You : (Write it down against the customer's page in your paper note book) Stored. Call us any time for knowing your neighbor ' s birthday again!

· Customer:thank you!

· You:no problem! We charged your credit card with $0.1

So your call is usually like this:

? Customer: Hi! Can you remember my neighbor's birthday?

? You: Sure, what time is his birthday?

? Client:January 2nd

? You:(in the notebook on the customer's page down ) remember! If you want to know his birthday, call us anytime!

? Customer: Thank you!

? You are welcome, your credit card will be paid $0.1.

Chapter 2:you scale up:

Your Venture gets funded by YCombinator. Your idea was so simple, needs-a paper notebook and phone, yet so effective that it spreads like wild fire. You start getting hundreds of call every day.

And there starts the problem. You see this more and more than your customers has the to-wait in the queue to speak. Most of them even hang up tired of the waiting tone. Besides when you were sick, the other day and could don't come to work for you lost a whole day's business. Mention all those dissatisfied customers, who wanted information on the day.
You decide it's time for your to scale up and bring in your wife to help you.

Chapter II: Expansion of the company

You've got YC's investment. The idea is so simple, just a pen and a phone, but as fast as a prairie fire. You are getting hundreds of calls every day. But the problem also comes along. You find that more and more customers are waiting for you to answer. They were all fed up with waiting. And when you are sick and unable to work, you will lose a whole day's business, not to mention the dissatisfaction of those customers. So you decide: it's time to pull your wife over to help.

Your start with a simple plan:

1. You and your wife both get an extension phone

2. Customers still dial (555) –55-remem and need to remember only one number

3. a PBX would route the a customers call to whoever are free and equally

Your plan is simple:

1. You and your wife both have extension numbers.

2. The customer still dials the original number

3. The switch will send the customer a call to the two of you who are free.

Chapter 3:you has your first "bad Service":

The implemented the new system, you get a call from your trusted customer Jhon. How it goes:

· Jhon:hey

· You:glad you called "Remembrance inc!". What can I do for you?

· Jhon:can are I flight to New Delhi?

· You:sure. 1 sec sir
(You look up your notebook)
(wow! there is no entry for "Flight date" in Jhon ' s page)!!!!!

· You:sir, I think there is a mistake. You never told us on your flight to Delhi

· jhon:what! I just called you guys yesterday! (Cuts the call!)

Chapter III: Bad Service for the first time

Just two days after the expansion, you received a call from an old customer Jhon:

? Jhon: Hi!

? You: Thank you for calling the memory company, what can I do for you?

? Jhon: Can you tell me when I flew to New Delhi for the first time?

? You: Of course, please wait a moment (you look through your notebook, but you do not find the flight on the Jhon page ).

? I'm sorry, sir, but I don't think you have told us about your flight to New Delhi.

? Jhon: What!? I called you yesterday! (Hang up )

How does that happen? Could Jhon be lying? Think about it for a second and the reason hits you! Could Jhon ' s call yesterday reached your wife? You go to your wife ' s desk and check her notebook. Sure enough it ' s there. Your wife and she realizes the problem too.

What a terrible flaw in your distributed design! Your Distributed system is not consistent! There could always is a chance that a customer updates something which goes to either you or your wife and when the next C all from the customer are routed to another person there'll not being a consistent reply from remembrance inc!

How could this happen? is Jhon lying? You suddenly think of the reason! Maybe jhon called your wife yesterday. So you went to her desk to check her notebook. Yes, that's the reason. You told your wife that she was aware of the problem. What a bad question! your distributed system is not consistent! The customer calls you or your wife, and then another person is connected, your memory company can not give a consistent response!

Chapter 4:you Fix the consistency problem:

Well, your competitors could ignore a bad service, and not you. You think all night in the bed when your wife are sleeping and come up with a beautiful plan in the morning. You wake up your wife and tell her:

"Darling This was what we were going to does from now"

· Whenever any one of us get a call for an update (when the customer wants us to remember something) before completing th E -Call We tell the other person

· This is the both of US note down any updates

· When there was call for search (when the customer wants information he had already stored) we don ' t need to talk with th e other person. Since Both of us has the latest updated information in both of our note books we can just refer to it.

Fourth: Fix consistency issues

Your competitors may overlook this problem, but you won't. When your wife fell asleep, you thought about it all night and finally came up with a beautiful plan in the early morning. You woke her up and said:

"Honey, this is what we're going to do from now on:"

? Either one of us gets a call from the client asking for a note, and we're going to tell the other guy before we call.

? So we can both write down any updates.

? When a customer asks for a search, we don't need to ask each other because all the updates are recorded on our notebooks.

There is a problem though, you say, and so is an "update" request have to involve both of us and we cannot work in Parallel during that time. For eg. When you get a update request and telling me to the update too, I cannot take the other calls. But that's okay because most calls we get anyway is "search" (a customer updates once and asks many times). Besides, we cannot give wrong information at any cost.

"Neat" Your wife says, "but there was one more flaw in the this system, so you haven ' t thought of. What is the if one of us doesn ' t particular day? On this day, then, we won ' t is able to take "any" Update calls, because the other person cannot be updated! We'll have availability problem, i.e, for eg., if a update request comes to me I'll never be able to complete th At call because even though I has written the update in my note book and I can never update you. So I can never complete the call! "

However, there is still a problem, the customer asked to remember the call needs both of us to deal with, so that period of time can not work in parallel. For example, when you receive a save or update request, you'll also be told that I won't be able to answer other calls. But since most calls are found, there is no big problem (the customer updates and then looks for multiple times ). And we have to avoid remembering things at all costs.

"Very good!" "Your wife said, " but there's one more question you didn't expect. What if one of us can't come to work? We won't be able to accept an updated call on that day because another person can't write down the update. So we're going to have usability problems! For example, I can't complete this request when I receive an update , because even if I write it down in my notebook, I can't tell you. So I can't finish this call .

Chapter 5:you come up with the greatest solution ever:

You being to realize a little bit in why distributed system might is as easy as you thought at first. Is it, difficult to come up with a solution this could be both "consistent and Available"? Could is difficult for others, and not for you!! Then next morning your come up with a solution that your competitors cannot think of in their dreams! You wake your wife up eagerly again.

"Look". "This was what we can do to be consistent and available". The plan is mostly similar to what I told you yesterday:

· i) whenever any one of us get a call for an update (when the customer wants us to remember something) before completing The call, if the other person was available we tell the other person. This is the both of us note down any updates

· II) But if the other person was not a available (doesn ' t report to work) we send the same person an email about the Updat E.

· III) The next day is the other person comes-work after taking a day off, He first goes through all the emails, up Dates his note book accordingly. Before taking his first call.

The fifth chapter: the best solution

You're kind of aware of why distributed systems are not as simple as you might think at first. Is it difficult to come up with a plan that is both consistent and usable? It may be hard for other people, but not for you! The next morning, you came up with a solution that your competitors never dreamed of. You woke your wife up again in earnest.

See " you tell her," That's the way we're both consistent and usable, and the plan is much like what I told you yesterday :

? Either of us who receives a call from a customer asking to remember something, we have to tell another person before we finish the call so that we can both write down any updates.

? But if another person is absent, we send him an updated e-mail.

? The next day when he came to work, he looked through the mails and updated them to his book before processing any incoming calls.

Genius! You wife says! I can ' t find any flaws in this systems. Let's put it to use. Remembrance inc! is now both consistent and available!

Genius, man! Your wife said. This plan doesn't surprise any problems. Let's just do it! The memory company is now both consistent and usable!

Chapter 6:your wife gets angry:

Everything goes well for a while. Your system is consistent. Your system works well even when one of your doesn ' t report to work. But what if Both of the doesn ' t update the other person? Remember All those days you ' ve been waking your wife to early with your greatest-idea-ever-bullshit? * What if the Your wife decides to take calls, but are too angry with you and decides don't to update? Your idea Totally breaks! Your is good for consistency and availability are not Partition tolerant!*
You can decide to is partition tolerant by deciding don't to take any calls until your patch up with your wife. Then your system is not being "available" during that time ...

Sixth chapter: Wife's anger

Everything went well. Your system is consistent and works well when one of the two of you is unable to work. But what if you all came to work but didn't tell the other person about the update? Think about waking up your wife and saying what you call great ideas. If one day she answered the phone but was angry and didn't tell you to update it? your method is completely ruined. So far, your approach has been consistent and usable, but not partition tolerant. you can not answer any calls before you and your wife, so your system is not available at that time ...

Chapter 7:conclusion:

So let's look at the CAP theorem now. Its states, if you were designing a distributed system can get cannot achieve all three of consistency, Availabi Lity and Partition tolerance. You can pick only:

· Consistency:you customers, once they has updated information with you, 'll always get the most updated information When the they call subsequently. No matter how quickly they call back

· Availability:remembrance INC always is available for calls until all one of you or your wife .

· Partition tolerance:remembrance INC would work even if there are a communication loss between you and your wife!

The Sixth chapter: summary

Let's look at the cap theory now. It says: When you design a distributed system, you can only achieve consistency, availability, and partition tolerance in both:

? Consistency: When your customers call again, they'll always find the information they just called, no matter how short.

? Availability: No matter who you and your wife are working for, the memory company will always answer calls and process customer requests.

? Partition tolerance: Even if you and your wife lose the joint, the memory company can still function normally

bonus:eventual consistency with a run around clerk:

Here's another food for thought. You can have a run around clerk, who would update other's notebook when one of the your ' s or your wife ' s note books is updated. The greatest benefit of this was that, he can work in background and one of the your or your wife ' s "Update" doesn ' t has to B Lock, waiting for the other one to update. Many NOSQL systems work, one node updates itself locally and a background process synchronizes all other nodes accordingly ... The only problem is so you'll lose consistency of some time. For eg., a customer's call reaches your wife first and before the clerk have a chance to update your notebook, the custome R ' calls back and it reaches. Then he won ' t get a consistent reply. But the said, this is not at all a bad idea if such cases is limited. For eg., assuming a customer won ' t forget things so quickly this he calls back in 5 minutes.

Rewards: Eventual consistency and running staff

You can hire an employee to update another book when the content in a book is updated. The biggest benefit is that he can work in the background, you or your wife update without waiting for another to complete the update. That's how many NoSQL database systems work. A node is updated locally, and the background process synchronizes the update to all other nodes. The only problem is that you will lose a certain amount of time consistency. For example, the client calls your wife first, and the customer calls you when the updated employee does not complete the update of your book. Then he can't get a consistent response. But even so, it's not a bad idea in some cases. For example, a customer will not forget to forget things so quickly, usually five minutes or so before the call again.

That's CAP and eventual consistency for your in simple 中文版:)

This is a minimalist explanation of your cap theory and eventual consistency:)

Wonderful explanation of the CAP theory article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.