Spring Microservices in Action學(xué)習(xí)筆記 - On service discovery

The solution for a cloud-based microservice environment is to use a service-discovery mechanism that’s

  • Highly available—Service discovery needs to be able to support a “hot” clustering environment where service lookups can be shared across multiple nodes in a service discovery cluster. If a node becomes unavailable, other nodes in the cluster should be able to take over.
  • Peer-to-peer—Each node in the service discovery cluster shares the state of a service instance.
  • Load balanced—Service discovery needs to dynamically load balance requests across all service instances to ensure that the service invocations are spread across all the service instances managed by it. In many ways, service discovery replaces the more static, manually managed load balancers used in many early web application implementations.
  • Resilient—The service discovery’s client should “cache” service information locally. Local caching allows for gradual degradation of the service discovery feature so that if service discovery service does become unavailable, applications can still function and locate the services based on the information maintained in its local cache.
  • Fault-tolerant—Service discovery needs to detect when a service instance isn’t healthy and remove the instance from the list of available services that can take client requests. It should detect these faults with services and take action without human intervention.

1. The architecture of service discovery

  • Service registration—How does a service register with the service discovery agent?
  • Client lookup of service address—What’s the means by which a service client looks up service information?
  • Information sharing—How is service information shared across nodes?
  • Health monitoring—How do services communicate their health back to the service discovery agent?

Once a service has registered with a service discovery service, it’s ready to be used by an application or service that needs to use its capabilities. Different models exist for a client to “discover” a service. A client can rely solely on the service discovery engine to resolve service locations each time a service is called. With this approach, the service discovery engine will be invoked every time a call to a registered microservice instance is made. Unfortunately, this approach is brittle because the service client is completely dependent on the service discovery engine to be running to find and invoke a service.

A more robust approach is to use what’s called client-side load balancing. Figure 4.3 illustrates this approach.

In this model, when a consuming actor needs to invoke a service

  1. It will contact the service discovery service for all the service instances a service consumer is asking for and then cache data locally on the service consumer’s machine.
  2. Each time a client wants to call the service, the service consumer will look up the location information for the service from the cache. Usually client-side caching will use a simple load balancing algorithm like the “round-robin” load balancing algorithm to ensure that service calls are spread across multiple service instances.
  3. The client will then periodically contact the service discovery service and refresh its cache of service instances. The client cache is eventually consistent, but there’s always a risk that between when the client contacts the service discovery instance for a refresh and calls are made, calls might be directed to a service instance that isn’t healthy.
    If, during the course of calling a service, the service call fails, the local service discovery cache is invalidated and the service discovery client will attempt to refresh its entries from the service discovery agent.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末怕吴,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖农曲,帶你破解...
    沈念sama閱讀 217,907評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異憎茂,居然都是意外死亡,警方通過查閱死者的電腦和手機锤岸,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,987評論 3 395
  • 文/潘曉璐 我一進(jìn)店門竖幔,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人是偷,你說我怎么就攤上這事拳氢∧汲眩” “怎么了?”我有些...
    開封第一講書人閱讀 164,298評論 0 354
  • 文/不壞的土叔 我叫張陵馋评,是天一觀的道長凡辱。 經(jīng)常有香客問我,道長栗恩,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,586評論 1 293
  • 正文 為了忘掉前任洪燥,我火速辦了婚禮磕秤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘捧韵。我一直安慰自己市咆,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,633評論 6 392
  • 文/花漫 我一把揭開白布再来。 她就那樣靜靜地躺著蒙兰,像睡著了一般。 火紅的嫁衣襯著肌膚如雪芒篷。 梳的紋絲不亂的頭發(fā)上搜变,一...
    開封第一講書人閱讀 51,488評論 1 302
  • 那天,我揣著相機與錄音针炉,去河邊找鬼挠他。 笑死,一個胖子當(dāng)著我的面吹牛篡帕,可吹牛的內(nèi)容都是我干的殖侵。 我是一名探鬼主播,決...
    沈念sama閱讀 40,275評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼镰烧,長吁一口氣:“原來是場噩夢啊……” “哼拢军!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起怔鳖,我...
    開封第一講書人閱讀 39,176評論 0 276
  • 序言:老撾萬榮一對情侶失蹤茉唉,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后败砂,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赌渣,經(jīng)...
    沈念sama閱讀 45,619評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,819評論 3 336
  • 正文 我和宋清朗相戀三年昌犹,在試婚紗的時候發(fā)現(xiàn)自己被綠了坚芜。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,932評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡斜姥,死狀恐怖鸿竖,靈堂內(nèi)的尸體忽然破棺而出沧竟,到底是詐尸還是另有隱情,我是刑警寧澤缚忧,帶...
    沈念sama閱讀 35,655評論 5 346
  • 正文 年R本政府宣布悟泵,位于F島的核電站,受9級特大地震影響闪水,放射性物質(zhì)發(fā)生泄漏糕非。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,265評論 3 329
  • 文/蒙蒙 一球榆、第九天 我趴在偏房一處隱蔽的房頂上張望朽肥。 院中可真熱鬧,春花似錦持钉、人聲如沸衡招。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,871評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽始腾。三九已至,卻和暖如春空执,著一層夾襖步出監(jiān)牢的瞬間浪箭,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,994評論 1 269
  • 我被黑心中介騙來泰國打工辨绊, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留山林,地道東北人。 一個月前我還...
    沈念sama閱讀 48,095評論 3 370
  • 正文 我出身青樓邢羔,卻偏偏與公主長得像驼抹,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子拜鹤,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,884評論 2 354