![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Kubaka sisitemu yizewe, iraboneka cyane, yagabanijwe sisitemu isaba gukurikiza ubuhanga bwihariye, amahame, nuburyo. Igishushanyo mbonera cya sisitemu gikubiyemo gukemura ibibazo byinshi. Mubibazo byiganje kandi byibanze harimo ikibazo cyo kwandika kabiri .
"Ikibazo cyo kwandika kabiri" ni ikibazo kivuka muri sisitemu zagabanijwe, cyane cyane iyo zikorana namakuru menshi cyangwa data base zigomba kubikwa mugihe kimwe. Yerekeza ku ngorane zo kwemeza ko impinduka zamakuru zandikwa mububiko butandukanye bwamakuru, nkububiko cyangwa cashe, utabanje gutangiza ibibazo nkibidahuye namakuru, amakimbirane, cyangwa inzitizi zikorwa.
Microservices yububiko hamwe nububiko bwububiko kuri buri serivisi bizana inyungu nyinshi, nko kohereza no kwipima kwigenga, kunanirwa kwitaruye, hamwe no kuzamura umuvuduko witerambere. Ariko, ibikorwa bisaba impinduka muri microservices nyinshi, kuguhatira gutekereza kubisubizo byizewe kugirango ukemure iki kibazo.
Reka dusuzume ibintu aho domaine yacu irimo kwakira ibyifuzo byinguzanyo, kubisuzuma, hanyuma no kohereza imenyesha kubakiriya.
Dukurikije ihame rimwe ryinshingano, amategeko ya Conway, hamwe nuburyo bwo gushushanya ibyashizweho, nyuma yamasomo menshi yibasiwe nibyabaye, domaine yose yagabanyijwemo subdomain eshatu zifite imipaka isobanutse ifite imipaka isobanutse, imiterere ya domaine, nururimi rusanzwe.
Iya mbere ishinzwe kwicara no gukusanya inguzanyo nshya. Sisitemu ya kabiri isuzuma izi porogaramu kandi ifata ibyemezo bishingiye ku makuru yatanzwe. Iyi gahunda yo gusuzuma, harimo KYC / KYB, antifraud, hamwe no kugenzura ingaruka zinguzanyo, birashobora gutwara igihe, bisaba ubushobozi bwo gukemura ibihumbi nibisabwa icyarimwe. Kubwibyo, iyi mikorere yahawe microservice yabugenewe hamwe nububiko bwayo bwite, itanga igipimo cyigenga.
Ikigeretse kuri ibyo, iyi sisitemu iyobowe namakipe abiri atandukanye, buriwese ufite ukwezi kwayo kurekura, amasezerano yo murwego rwa serivisi (SLA), nibisabwa byapimwe.
Ubwanyuma , serivisi yihariye yo kumenyesha irahari kugirango yohereze imenyesha kubakiriya.
Dore ibisobanuro binonosoye byibanze byo gukoresha sisitemu:
Nuburyo bworoshye kandi bwibanze muburyo bwa mbere, ariko reka twibire muburyo serivisi yo gusaba inguzanyo itunganya itegeko ryo gusaba inguzanyo.
Turashobora gusuzuma uburyo bubiri bwo guhuza serivisi:
Ubwa mbere-bwibanze-Biyemeje-Hanyuma-Gutangaza: Muri ubu buryo, serivise ivugurura ububiko bwibanze (yiyemeje) hanyuma igatangaza ibyabaye cyangwa ubutumwa kubindi bikorwa.
Banza-Gutangaza-Hanyuma-Byibanze-Kwiyemeza: Ibinyuranye, ubu buryo bukubiyemo gutangaza ibyabaye cyangwa ubutumwa mbere yo gukora impinduka mububiko bwibanze.
Ubwo buryo bwombi bufite aho bugarukira kandi ni igice cyananiwe umutekano mu itumanaho muri sisitemu zagabanijwe.
Iki nigishushanyo gikurikirana cyo gukoresha inzira yambere.
Muri iki gihe, Serivisi ishinzwe Inguzanyo ikoresha uburyo bwa mbere-bwibanze-bwiyemezamirimo-hanyuma-Gutangaza , aho ibanza gukora transaction hanyuma ikagerageza kohereza imenyesha kurindi sisitemu. Nyamara, iyi nzira irashobora kunanirwa niba, nkurugero, hari ibibazo byurusobe, Serivisi ishinzwe gusuzuma ntishobora kuboneka, cyangwa Serivisi ishinzwe inguzanyo ihura nikibazo cyo kwibuka (OOM) ikagwa. Mu bihe nk'ibi, ubutumwa bwatakara, hasigara Isuzuma nta nteguza isaba ry'inguzanyo nshya, keretse niba hari izindi ngamba zashyizwe mu bikorwa.
Uwa kabiri.
Muburyo bwa mbere-Gutangaza-Hanyuma-Byibanze-Kwiyemeza , Serivisi ishinzwe Inguzanyo ihura ningaruka zikomeye. Irashobora kumenyesha Serivisi ishinzwe Isuzuma kubyerekeye porogaramu nshya ariko ikananirwa kubika iri vugurura mu karere kubera ibibazo nkibibazo byububiko, amakosa yo kwibuka, cyangwa amakosa ya code. Ubu buryo burashobora gutuma habaho ukudahuza gukomeye kwamakuru, bishobora gutera ibibazo bikomeye, bitewe nuburyo Serivisi ishinzwe Inguzanyo ikemura ibyifuzo byinjira.
Tugomba rero kumenya igisubizo gitanga uburyo bukomeye bwo gutangaza ibyabaye kubakoresha hanze. Ariko, mbere yo gucukumbura ibisubizo bishoboka, dukwiye kubanza gusobanura ubwoko bwubwishingizi bwogutanga ubutumwa bugerwaho muri sisitemu yatanzwe.
Hariho ubwoko bune bwingwate dushobora kugeraho.
Nta garanti
Nta cyemeza ko ubutumwa buzashyikirizwa iyo bugana. Inzira Yambere-Yibanze-Kwiyemeza-Hanyuma-Gutangaza nibyo rwose. Abaguzi barashobora kwakira ubutumwa rimwe, inshuro nyinshi, cyangwa ntanarimwe.
Igihe kimwe
Mugihe kimwe cyo gutanga bivuze ko ubutumwa buzashyikirizwa aho bugana mugihe kinini. Inzira Yambere-Yibanze-Yiyemeje-Hanyuma-Gutangaza irashobora gushyirwa mubikorwa murubu buryo hamwe na politiki yo kugerageza kugerageza nagaciro kamwe.
Nibura rimwe gutanga \ Abaguzi bazakira kandi batunganyirize ubutumwa bwose ariko barashobora kwakira ubutumwa bumwe inshuro zirenze imwe.
Nukuri igihe kimwe cyo gutanga \ Nukuri iyo gutangwa bivuze ko umuguzi yakira ubutumwa neza rimwe.
Muburyo bwa tekiniki, birashoboka kubigeraho hamwe na Kafka mubikorwa no gushyira mubikorwa bidasanzwe bidasubirwaho byakozwe nabaguzi.
Mu bihe byinshi, 'byibura rimwe' gutanga ibyemezo byemeza gukemura ibibazo byinshi byemeza ko ubutumwa butangwa byibuze rimwe, ariko abaguzi bagomba kuba badafite imbaraga. Nyamara, urebye kunanirwa kwurusobe rudashobora kwirindwa, ibitekerezo byabaguzi byose bigomba kuba bidafite imbaraga kugirango birinde gutunganya ubutumwa bwikopi, hatitawe ku ngwate yababikoze. Kubwibyo, iki gisabwa ntabwo ari inenge cyane kuko kigaragaza ukuri.
Hano haribisubizo byinshi kuri iki kibazo, bifite ibyiza nibibi.
Nk’uko Wikipedia ibivuga, Kwiyemeza Ibyiciro bibiri (2PC) ni protocole yagabanijwe ikoreshwa mu bumenyi bwa mudasobwa no mu micungire y’ububiko kugira ngo habeho guhuza no kwizerwa by’ibicuruzwa byatanzwe. Yashizweho mubihe aho ibikoresho byinshi (urugero, ububikoshingiro) bigomba kugira uruhare mubikorwa bimwe, kandi byemeza ko bose bakora transaction cyangwa bose bakayikuramo, bityo bikomeza guhuza amakuru. Byumvikane neza nibyo dukeneye, ariko ibyiciro bibiri-byiyemeje bifite ibibi byinshi:
Igisubizo kigaragara cyane kuri microservices yububiko ni ugukoresha icyitegererezo (cyangwa rimwe na rimwe kirwanya-icyitegererezo) - base base base. Ubu buryo ni intiti cyane niba ukeneye guhuza ibikorwa kumeza menshi mumibare itandukanye, koresha gusa base base imwe kuri microservices.
Ingaruka zubu buryo zirimo kumenyekanisha ingingo imwe yo gutsindwa, kubuza gupima ububiko bwigenga, no kugabanya ubushobozi bwo gukoresha ibisubizo bitandukanye byububiko bikwiranye nibisabwa byihariye no gukoresha imanza. Byongeye kandi, guhindura codebase ya microservices byaba ngombwa kugirango dushyigikire ubwo buryo bwo kugabura.
' Transactional outbox ' ni igishushanyo mbonera gikoreshwa muri sisitemu zagabanijwe kugirango hamenyekane ubutumwa bwizewe, kabone niyo haba hari ubutumwa bwizewe. Harimo kubika ibyabaye mumeza yabigenewe 'OutboxEvents' mubikorwa bimwe nibikorwa ubwabyo. Ubu buryo buhuza neza nibintu bya ACID byimibare yububiko. Ibinyuranyo, imibare myinshi No-SQL ntabwo ishyigikira byimazeyo imitungo ya ACID, ihitamo ahubwo amahame ya CAP theorem na filozofiya ya BASE, ishyira imbere kuboneka no guhuzagurika kuruta guhuzagurika gukomeye.
Isanduku yo kugurisha itanga byibura garanti imwe kandi irashobora gushyirwa mubikorwa hamwe nuburyo bwinshi:
Umurizo wo kugurisha
Amatora
Uburyo bwo kugurisha ibicuruzwa bisobanura gukoresha imibare yihariye ya CDC (Guhindura Data Ifatwa). Ingaruka nyamukuru zubwo buryo ni:
Ububikoshingiro bwibisubizo byihariye
Kongera ubukererwe kubera umwihariko wa CDC ishyirwa mubikorwa
Ubundi buryo ni Amatora yatangajwe , yorohereza gupakurura hanze mugutora ameza yo hanze. Ingaruka yibanze yubu buryo nubushobozi bwo kongera ububiko bwububiko, bushobora kuganisha kumafaranga menshi. Byongeye kandi, ntabwo imibare yose No-SQL ishyigikira kubaza neza ibyiciro byihariye. Gukuramo inyandiko zose birashobora rero kuvamo imikorere mibi.
Hano hari igishushanyo gito gikurikirana gisobanura uko gikora.
Ikibazo cyibanze hamwe na Transactional Outbox yerekana uburyo bushingiye kumiterere ya ACID. Birashobora kuba byoroshye muburyo busanzwe bwa OLTP ariko bigatera ibibazo mubice bya NoSQL. Kugira ngo iki kibazo gikemuke, igisubizo gishoboka ni ugukoresha umugereka (urugero, Kafka) uhereye mugutangiza ibyifuzo.
Aho gutunganya mu buryo butaziguye itegeko ryo 'gutanga inguzanyo isaba', duhita twohereza ku ngingo ya Kafka y'imbere hanyuma dusubize igisubizo 'cyemewe' kubakiriya. Ariko, kubera ko bishoboka cyane ko itegeko rigikeneye gutunganywa, ntidushobora guhita tumenyesha umukiriya ibisubizo. Kugirango ucunge ibi byanyuma, turashobora gukoresha tekinike nkamatora maremare, gutora-umukiriya watowe, ibyiringiro bya UI, cyangwa gukoresha WebSockets cyangwa Server-yoherejwe ibyabaye kubimenyeshwa. Ariko, iyi ni ingingo itandukanye rwose, reka rero dusubire kumutwe wambere.
Twohereje ubutumwa kumutwe wa Kafka imbere. Serivisi ishinzwe Inguzanyo noneho ikoresha ubu butumwa - itegeko rimwe ryakiriye umukiriya - hanyuma ritangira gutunganywa. Icya mbere, ikora logique yubucuruzi; gusa nyuma yiyi logique ikozwe neza kandi ibisubizo bikomeje, itangaza ubutumwa bushya kumutwe rusange wa Kafka.
Reka turebe gato kuri pseudo-code.
public async Task HandleAsync(SubmitLoanApplicationCommand command, ...) { //First, process business logic var loanApplication = await _loanApplicationService.HandleCommandAsync(command, ...); //Then, send new events to public Kafka topic producer.Send(new LoanApplicationSubmittedEvent(loanApplication.Id)); //Then, commit offset consumer.Commit(); }
Byagenda bite niba gutunganya logique yubucuruzi binaniwe? Nta mpungenge, kuva offset itarakozwe, ubutumwa buzongera.
Byagenda bite niba kohereza ibintu bishya muri Kafka binaniwe? Nta mpungenge, kubera ko logique yubucuruzi idafite imbaraga, ntabwo izashiraho inguzanyo ebyiri. Ahubwo, izagerageza kohereza ubutumwa kumutwe rusange wa Kafka.
Byagenda bite niba ubutumwa bwoherejwe i Kafka, ariko offset yiyemeje bikananirana? Nta mpungenge, kubera ko logique yubucuruzi idafite imbaraga, ntabwo izakora gusaba inguzanyo ebyiri. Ahubwo, izohereza ubutumwa kumutwe rusange wa Kafka kandi twizere ko offset yiyemeje izatsinda iki gihe.
Inzitizi nyamukuru zubu buryo zirimo kongeramo ibintu bigoye bifitanye isano nuburyo bushya bwo gutangiza gahunda, amaherezo ahoraho (kubera ko umukiriya atazahita amenya ibisubizo), hamwe nibisabwa kugirango logique yubucuruzi ibe idafite imbaraga.
Inkomoko y'ibyabaye ni iki, kandi ni gute ishobora gukoreshwa hano? Inkomoko y'ibyabaye ni software yububiko bukoreshwa mugushushanya imiterere ya sisitemu ifata impinduka zose kumibare yayo nkurukurikirane rwibintu bidahinduka. Ibi bintu byerekana ukuri cyangwa inzibacyuho ya leta kandi ikora nkisoko imwe yukuri yukuri kuri sisitemu y'ubu. Muburyo bwa tekiniki, mugushira mubikorwa sisitemu yo gushakisha ibintu, dusanzwe dufite ibyabaye byose muri EventStore, kandi iyi EventStore irashobora gukoreshwa nabaguzi nkisoko imwe yukuri yibyabaye. Ntibikenewe ko habaho igisubizo cyihariye kugirango gikurikirane impinduka zose cyangwa impungenge zijyanye no gutumiza, ikibazo cyonyine cyicaye kuruhande rusomwe kuva kugirango ubashe kubona imiterere nyayo yikigo isabwa gusubiramo ibyabaye byose.
Muri iyi ngingo, twasuzumye uburyo bwinshi bwo kubaka ubutumwa bwizewe muri sisitemu zagabanijwe. Hano hari ibyifuzo byinshi dushobora gusuzuma mugihe twubaka sisitemu hamwe nibi biranga
Igihe gikurikira, tuzareba urugero rufatika rwo gushyira mubikorwa Transactional Outbox. Reba
wowe!