

Hinted Handoff
distributed system pattern
Terminology
- Node : 다른 서비스들에게 기능을 제공하는 서버
- Coordinator Node: 클러스터 중에서 요청을 처리할 노드를 선정하는 노드
Requirements
Design a distributed system pattern with the following characteristics:
Functional Requirements
- 일시적인 노드 장애를 감내해야 함
- 구현이 쉬워야함
Non-Functional Requirements
- 높은 쓰기 가용성
- 결과적 일관성(eventually consistent)
- 확장성
높은 고가용성 아키텍쳐란 무엇인가?
높은 장애 감내성과 SPOF를 제거하기 위한 이유로 분산 시스템이 인기를 얻어가고 있다.
분산 시스템은 고가용성을 위해 일관성을 조금 희생하면서 데이터를 복제한다
고가용성의 분산 데이터 저장소(DynamoDb, Apache Cassandra)는 결과적 일관성 모델을 구현함
고가용성의 아키텍처를 가진 시스템은 피크 타임에도 최적의 성능을 유지할 수 있어야 한다. 고가용성은 서비스가 클라이언트에게 얼마나 이용가능하게 유지되는지의 시간으로 측정이 된다.
Hinted handoff explained
노드의 가용성은 하드웨어 장애, 메모리 소진, 네트워크 파티션, GC pause 등의 요소들의 곱셈으로 결정이 된다
특정 데이터셋을 저장하는 책임이 있는 노드를
target node
target node 대신에 임시적으로 특정 dataset을 저장하는 노드를
backup node
(= coordinator node)backup 노드가 target node가 장애상황일 때, hint(data + metatdata of target node)를 저장함
결과적 일관성이 target node가 장애상황에서 복구되었을때, backup node로 부터 hint가 전달되면서 달성이 된다.
hinted handoff는 쓰기 상황에서 복구를 수행하기 위한 분산 시스템 패턴이다.
hinted handoff 패턴은 결과적 일관성(eventual consistency)과 일시적 노드 장애에 대해 향상된 가용성을 제공한다. 이 패턴으로 인해 시스템은 capacity는 줄어들더라도 같은 양의 write operation을 수행할 수 있다
high-level workflow
- 가십 프로토콜로 시스템의 노드 장애를 감지
- 장애 노드는 이용불가하다고 마크됨
- 이용불가한 target node로의 요청은 backup 노드로 redirect 됨
- backup 노드는 data 와 target node에 대한 metadata를 hint안에 저장함
- 이용불가한 target node에 대한 상태는 gossip protocol로 결정
- target node 가 다시 원상복구됨
- backup node는 hint를 target node에게 전달함
- target node는 data mutation을 replay 함
- the backup node removes the hints
힌트의 저장위치는 시스템 구현에 따라 다름
예를들어 Apache Cassandra는 hint를 backup node에 일정 시간 frame에 대해서 저장함. backup node는 hint를 disk-based storage로 수초 마다 flush함. 또는 replay performance를 높이기 위해 hint를 각 노드의 local directory에 나누어 저장
backup node는 target node가 어느 특정 기간 이상으로 이용불가능한상태면 hint를 저장하기 거부함. target node가 cluster에서 제외되면 backup node는 hint 를지워야 함
고가용성의 아키텍처를 구현하기 위한 다른 대안으로는 apache kafka 와 같은 log-based journaling service를 이용하여 shared-nothing 접근법을 사용하는 것이다. 이 방식으로, data는 db에 쓰여지기 전에 durable journal에 들어가게 된다.
Sloppy Quorum and Hinted handoff
전통적인 정족수 기반 접근법은 network partition이 발생했을 때나 여러개의 target node가 장애상황이 발생했을 때 시스템의 가용성을 떨어뜨린다. 즉, 전통적인 정족수 기반 접근법은 fault-tolerant 하지 않다.
sloppy quorum은 quorum 기반 접근법의 변형으로 다수개의 target node가 이용불가능 할 때, hinted handoff 패턴이 quorum에 도달하도록 도와준다(leverage)
주된 결점은 노드가 서로 소통을 하지 않았을 때, 읽기 연산이 stale data를 반환할 수 있다는 것. 게다가 backup node가 target node로 hint를 보내기 전에 크래시가 나면 시스템의 내구성 또한 타협될 수 있다는 것
Hinted handoff data model
The backup node stores the hints in the hints table on durable disk-based storage
- ID: identifier of the data mutation
- target_node_id: identifier of the unavailable target node
- version_id: version of the database system
- timestamp: determines the hint TTL
- data: data mutation stored as a blob
Hinted Handoff Use cases
The popular use cases of the hinted handoff are as follows
- Distributed databases - Apache Cassandra and Amazon Dynamo
- Content delivery networks (CDN) redirect the traffic to the healthy nodes