Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of CAP Theorem

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shares with you the content of an example analysis of CAP's theorem. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Memory Inc.

A genius idea comes into your mind: since people's memories are usually bad, and I'm good at memory, why don't I use my memory talent to start a career?

Act immediately, you have created the opening advertisement of memory Company:

Remembrance Inc!-Never forget, even without remembering!

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

When you need to remember something, just call 555-55-REMEM and tell us what 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 to 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.1per request

Memorize the company's daily business phone records:

Customer: Hello, can you store my neighbor's birthday?

You: yes, you say.

Customer: January 2nd

You: record (write down the information on the customer page of the notebook). OK, welcome to inquire next time.

Customer: thank you

You: please pay 1 yuan

two。 Business expansion

With creativity and character, the memory company is getting bigger and bigger, and the cost is only laptops and telephones.

When you are sick and unable to work one day, you will lose a day's income, not to mention customers who want information that day will go crazy.

You have a new plan:

1. You and your wife use extensions separately.

2. (555)-55-REMEM customer service number remains the same

3. The customer service call will be transferred to an available extension.

3. The first business downtime

One day you receive a phone call from an old customer, Luo Zhixiang, asking to inquire about "tomorrow's appointment".

You are blinded, I don't know, there is no such information on your memory page; the customer hung up the phone with a bang.

Looking back on that day, I guess Luo Zhixiang called my wife on the business phone yesterday, and this is indeed the case.

You are all aware of the new problems caused by the extension.

What a terrible flaw in distributed design! Your distributed system is inconsistent! There will always be a time when the customer will make a business call to one of you; on the next dial, the customer may receive inconsistent information.

4. Fix consistency issu

When it's time to blow before going to bed, you have an idea:

When one of us receives a new memory service from a customer, we will tell the other person before we hang up.

So that we can all write down the new business in our notebooks.

When customers inquire, both of us can easily deal with it.

Here's a problem: when one of them receives a new business call, they can't work in parallel.

For example, when you receive new business and tell me to record information, I can't take other calls.

But this is not a big problem, because most of them are inquiries (you can redial the phone and try again), and our first priority is to make sure the information is correct.

Your wife further said: if one day you are not on duty, I receive new business, your notebook can not get the latest information, there will be usability problems, because I failed to inform you, I can not hang up the phone to complete this business.

5. Better scheme

You have come to understand "consistency" and "availability" in distributed systems. You came up with a better plan:

1. When you receive a new business call, notify the other party before you hang up, so that both people can write down the message.

two。 One day one of them was not on duty, and the other received a new business call and sent an email to those who were absent.

3. The next day, those who are absent from work go to work to check their email and update their notebooks.

Nice, consistency and availability are now satisfied.

6. It is difficult to raise a wife.

With the optimization scheme, everything is going well, your notebooks are consistent, and the system works well when one of you is not on duty.

However, everything happens, but one day you are all on duty, but your wife thinks your dishes are not clean and doesn't want to talk to you today. If she receives new business and doesn't notify you, there will be something wrong with your inquiry business.

Your solution includes "consistency" and "usability", but does not satisfy "partition fault tolerance".

In order to meet the "partition fault tolerance", you can go offline (until you repair the relationship) and let your wife take over the business alone, but your system will not be available.

7. Conclusion

Let's go back to CAP's theorem: when designing a distributed system, you can only satisfy two "consistent Consistency", "availability Availability" and "partition fault-tolerant Partition Tolerance".

? Consistency: once you have accepted the customer's new business, you must get the latest information when the customer makes subsequent inquiries.

Availability: as long as one of you is on duty, memory Company will always provide services.

Partition Tolerance: your husband and wife are in conflict, and the memory company is still in operation.

With such a scene, it is not difficult to understand CP, AP and CA.

Hire tool people-- > final consistency

Hire a tool person to update the notebook of the unupdated person. Compared to your wife notifying you of the update in real time, this tool person has the advantage of running errands backstage, and neither of you will block your business.

This is how many NoSql work: one node is updated locally and the background process is synchronized to other nodes. The only problem is that consistency is lost a few times.

Your wife received the new business, and before the tool person had time to run errands, the customer immediately called back and transferred to your extension, and you gave an inconsistent answer. This situation is limited because customers don't forget things so quickly.

This is the realistic explanation of CAP theorem and ultimate consistency.

Thank you for reading! This is the end of this article on "example Analysis of CAP Theorem". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 237

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report