메뉴
HN
Hacker News 51일 전

영화 'Mean Girls'로 배우는 Raft 합의 알고리즘

IMP
5/10
핵심 요약

이 글은 분산 시스템에서 데이터를 안전하게 복제하고 일관성을 유지하는 'Raft 합의 알고리즘'을 영화 'Mean Girls'의 학교 내 파벌에 빗대어 쉽게 설명합니다. 리더 선출과 데이터 복제의 중요성을 주인공 레지나와 '플라스틱스' 그룹의 관계로, 그리고 과반수 투표(Quorum)의 필수성을 다른 소수 파벌과의 비교를 통해 직관적으로 보여줍니다.

번역된 본문

Raft 합의 알고리즘(Raft Consensus Algorithm) 때문에 개인적으로 고통받아 본 적이 있다면 손을 들어보세요. Raft를 이해하는 것은 꽤 어려울 수 있습니다. 실제로 최근 소셜 미디어에서 인프라 기업의 실제 기술 리더들조차 이에 대한 이해도가 부족한 모습을 보이는 것을 목격했습니다(!). 요점은, 당신만 어려워하는 게 아니라는 뜻입니다. 그럼 가자, 루저들, (할리우드) 고등학교로 돌아가보자고요.

그래서, Raft가 도대체 뭘까요? Raft는 분산 시스템에서 데이터가 안전하고 일관되게 복제되도록 보장하기 위해 사용하는 합의 알고리즘입니다. 이 문장 하나만으로도 헷갈릴 수 있습니다. 이 글에 담긴 비유가 사람들이 Raft의 작동 방식을 이해하는 데 도움이 되기를 바랍니다. 국가적인 'Mean Girls'의 날("10월 3일, 그는 나에게 오늘이 며칠이냐고 물었어요")을 기리기 위해, 저는 영화 'Mean Girls'를 통해 설명하는 Raft 합의 알고리즘을 소개합니다. (Raft에 대한 훌륭하고 기술적인 개요를 원한다면 'The Secret Lives of Data'를 추천합니다.)

Raft 합의는 고등학교의 파벌을 통해 설명될 수 있으며, 이를 보여주기에 'Mean Girls'만 한 작품이 없습니다. 영화 초반에 캐디는 '홈스쿨링을 받는 정글 괴짜'이며, 따라서 어느 파벌에도 속하지 않습니다. 그녀는 복제본(replica)이 없는 단 하나의 데이터 조각과 같습니다. 만약 그녀가 커다란 노란 스쿨 버스에 치인다면, 군바지와 샌들에 대한 그녀의 생각은 그녀와 함께 사라져 버리고 유행할 수 없을 것입니다.

하지만 '플라스틱스(The Plastics)'는 클러스터(cluster)의 일부입니다. 레지나가 스쿨 버스에 치이더라도, 그녀가 가졌던 정보는 그녀와 함께 사라지지 않습니다. 왜냐하면 이미 카렌과 그레첸에게 그 정보를 공유했기 때문입니다. 누군가 '번 북(Burn Book)'을 찾고 있다면, 레지나가 병원에서 회복하는 동안에도 나머지 두 멤버 중 한 명에게 물어봄으로써 찾을 수 있습니다. 만약 그녀가 그 지식을 복제하지 않았다면, 아무도 그 책의 위치를 찾을 수 없었을 것입니다.

모든 복제본 클러스터에는 Raft 리더, 즉 '여왕벌(Queen Bee)'이 필요합니다. 물론 이 역할은 레지나 조지입니다. 레지나는 그레첸 위너스(그녀의 아버지가 토스터 스트루델을 발명했으며 그녀의 머리카락은 비밀로 가득 차 있음)와 카렌 스미스(그녀는 그렇게 똑똑하지는 않지만 날씨를 예보하는 초능력을 가짐)로 구성된 '플라스틱스' 그룹의 리더입니다. 그레첸과 카렌은 팔로워(follower) 복제본입니다.

이 역학 관계는 복제본들 사이에 합의(consensus)가 이루어지지 않으면 어떠한 행동도 취할 수 없다는 점에서 Raft와 매우 유사합니다. 즉, 친구들에게 먼저 물어보지 않고는 스커트를 사지 않을 거잖아요, 그렇죠? 바로 그겁니다! 그것이 바로 다수결 투표, 즉 합의가 필요한 이유입니다. 레지나가 쇼핑을 하면서 스커트를 사고 싶다면, 그레첸이나 카렌 중 한 명이 그 구매를 승인하지 않는 한 그녀는 그렇게 할 수 없습니다.

레지나가 그레첸과 카렌에게 수요일에는 분홍색 옷을 입어야 한다고 말한다고 가정해 봅시다. 그레첸이 먼저 열렬히 승인합니다. 이제 레지나가 그레첸의 확인을 받았으므로, '플라스틱스'의 과반수(3분의 2)가 수요일에 분홍색을 입는 것에 찬성하게 되고 합의에 도달하게 됩니다. 이제 공식적으로 확정된 것입니다.

Raft에서의 쿼럼(Quorum, 정족수) 이해하기 'Mean Girls'의 고등학교 환경은 다양한 파벌로 구성되어 있습니다. 일반적으로 이러한 파벌들은 점심시간에 각각 모여 앉으며, 테이블 사이에는 섞이는 일이 없습니다. 이 테이블 사이의 공간을 '플라스틱스'와 '아트 프릭스(Art Freaks)'(일명 "당신이 만나 볼 수 있는 가장 위대한 사람들") 사이의 의도적인 분단(Schism)이라고 생각해 봅시다.

계산을 쉽게 하기 위해 '플라스틱스'는 3명, '아트 프릭스'는 2명(다미안과 재니스)으로 생각해 보겠습니다. 한 클라이언트가 '플라스틱스'에게 메시지를 전달함과 동시에, 다른 클라이언트가 '아트 프릭스'에게 메시지를 전달했다고 가정해 봅시다. '글렌 코코 4개'라는 메시지는 '플라스틱스' 파벌/노드(Raft 리더인 레지나를 통해)에게 보내졌고, '그레첸 위너스 0개'라는 메시지는 '아트 프릭스' 파벌/노드(Raft 리더인 재니스를 통해)에 기록되었습니다.

'아트 프릭스'는 재니스와 다미안 단 두 명으로만 구성되어 있기 때문에 쿼럼(과반수)을 달성할 수 없습니다. 왜냐하면 투표 시 동점을 해결하려면 파벌의 구성원 수가 2명보다 많아야 하기 때문입니다. 쿼럼을 달성할 수 없으므로 커밋(commit)조차 할 수 없게 됩니다.

반면, 레지나의 파벌은 구성원이 2명보다 많기 때문에(3명), 레지나는 과반수를 확보하고 '글렌 코코 4개'라는 변경 사항을 성공적으로 커밋할 수 있었습니다.

원문 보기
원문 보기 (영어)
Raise your hand if you’ve ever been personally victimized by the Raft Consensus Algorithm. Understanding Raft can be tough. In fact, I’ve seen conversations recently on social media in which actual technical leaders of infrastructure companies demonstrate a lack of understanding (!). Point being, you’re not alone. Get in, losers, we’re going back to (Hollywood) high school. So, like, what is Raft? Raft is a consensus algorithm used in distributed systems to ensure that data is replicated safely and consistently. That sentence alone can be confusing. Hopefully the analogy in this post can help people understand how it works. In honor of national Mean Girls day (“on October 3rd he asked me what day it was”), I present the Raft Consensus Algorithm as explained through the movie Mean Girls . (For a great, more technical overview of Raft, we recommend The Secret Lives of Data ). Raft consensus can be explained using cliques in high school, and nothing does it better than Mean Girls . In the beginning of the movie, Cady is a “home-schooled jungle freak” and thus is not a member of a clique. She is a lone piece of data with no replicas. If she were to be hit by a big yellow school bus, her thoughts on army pants and flip flops would die with her and would never trend. The Plastics however, are part of a cluster. If Regina is hit by a school bus, the information she had wouldn’t die with her, since she had already shared it with Karen and Gretchen. If someone were looking for the Burn Book, they could find it by asking one of the remaining two members, even while Regina was recovering in the hospital. If she hadn’t replicated that knowledge, nobody would ever be able to locate the book. Every cluster of replicas needs to have a Raft leader, or a Queen Bee. Of course, this would be Regina George. Regina is the leader of the Plastics, a group comprised of Gretchen Wieners (her father invented Toaster Strudel and her hair is full of secrets) and Karen Smith (she’s not the brightest bulb and she has weather forecasting superpowers). Gretchen and Karen are the follower replicas. This dynamic is similar to Raft in that if there isn’t consensus among replicas, no action can be taken. I mean, you wouldn’t buy a skirt without asking your friends if it looks good on you first, right? Exactly! That’s why you need consensus, or the majority vote. If Regina is shopping and wants to buy a skirt, she can’t do so unless either Gretchen or Karen has signed off on the purchase. Let’s say Regina tells Gretchen and Karen that on Wednesdays they wear pink. Gretchen eagerly approves first. Now that Regina has Gretchen’s confirmation, the majority of the Plastics (⅔) are in favor of wearing pink on Wednesdays, and consensus has been reached. Now it’s official. Understanding Quorum in Raft The high school environment of Mean Girls is comprised of many different cliques. Typically these cliques each sit together at lunch, with no intermingling between tables. Let’s think of the space between tables as a deliberate schism between the Plastics and the “Art Freaks” (also known as “the Greatest People You Will Ever Meet.”) Let’s make numbers easy and think of the Plastics as having 3 people and the Art Freaks as having 2 people, Damien and Janice. Let’s say a client delivered a message to the Plastics at the same time as another client delivered a message to the Art Freaks. ‘4 for Glenn Coco’ was sent to the Plastics clique/node (through Regina, the Raft leader ), and ‘0 for Gretchen Wieners’ was written to the Art Freaks clique/node (through Janice, the Raft leader). Since the Art Freaks are made up of only two people, Janice and Damien, they are not able to achieve a quorum, since the clique needs more than two members in order to resolve a tie when voting. Since they can’t achieve a quorum, the commit can’t even be made. However, because her clique has greater than two members (3), Regina was able to secure a majority and commit the change ‘4 for Glenn Coco.’ Leader Election: Who Gets to Be the Raft Leader? When Regina shows up to lunch wearing sweatpants on a Monday she is dramatically booted from her role as leader of the Plastics. At given intervals, a leader must send out a sort of heartbeat to maintain their leadership status. This is their way of saying “hi, I’m still here.” Similarly, any deserving Queen Bee needs to send out cues of their dominance at regular intervals, and when Regina can no longer assert her status, she is no longer the Queen Bee. The Plastics need a new Raft leader, obviously. Luckily, Cady Heron steps up as the candidate replica, and Gretchen and Karen each reply with their vote to ensure Cady is the new Queen Bee. Now, the Plastics can’t do anything without Cady’s direction first. When Cady dresses in army pants and flip flops, she only needs one other member of the Plastics to agree that it’s cool to achieve a quorum (with 2 out of 3 votes), and now her style is accepted by all. The state of their high school has become “army pants and flip flops.” Since Cady is now the Queen Bee, or Raft leader, requests from the client will go to Cady first. Let’s say Damien is the client speaking to Cady when the entire class of junior girls is in the gymnasium. Damien shouts “she doesn’t even go here!” Because Cady is the Raft leader, she should be the one to receive this piece of information, and relay it to the rest of the Plastics. Once she has confirmation from at least one of the other Plastics, the information has been committed. Does she even go here? No, she just has a lot of feelings. Karen knows she doesn’t go here, Gretchen knows she doesn’t go here, Ms. Norbury knows she doesn’t go here, Janice Ian knows she doesn’t even go here. Everyone knows she doesn’t even go here. Hopefully this makes the Raft consensus algorithm more relatable. With this level of consistency in CockroachDB, the limit does not exist! How fetch is that?