![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Ukwakha inkqubo ethembekileyo, efumanekayo kakhulu, nenokwabiwa ngokukhawuleza kufuna ukubambelela kubuchule obuthile, imigaqo kunye neepateni. Uyilo lweenkqubo ezinjalo lubandakanya ukujongana nemingeni emininzi. Phakathi kweyona miba ixhaphakileyo nesisiseko yingxaki yokubhala kabini .
"Ingxaki yokubhala kabini" ngumngeni ovela kwiinkqubo ezisasazwayo, ngokukodwa xa ujongene nemithombo yedatha emininzi okanye i-database efuna ukugcinwa kwi-sync. Ibhekisa kubunzima bokuqinisekisa ukuba utshintsho lwedatha lubhalwa rhoqo kwiivenkile zedatha ezahlukeneyo, ezifana nedathabheyisi okanye i-cache, ngaphandle kokwazisa imiba efana nokungahambelani kwedatha, iingxabano, okanye imiqobo yokusebenza.
Ulwakhiwo lwee-microservices kunye nedatabase yepatheni ngenkonzo nganye izisela izibonelelo ezininzi, ezinjengokusasazwa ngokuzimeleyo kunye nokukalwa, ukusilela okuzimeleyo, kunye nokonyuswa okunokwenzeka kwesantya sophuhliso. Nangona kunjalo, imisebenzi ifuna utshintsho phakathi kwee-microservices ezininzi, kukunyanzela ukuba ucinge ngesisombululo esithembekileyo sokujongana nale ngxaki.
Masithathele ingqalelo imeko apho indawo yethu ibandakanya ukwamkela izicelo zemali-mboleko, ukuzivavanya, kunye nokuthumela izaziso kubathengi.
Ngomoya womgaqo-siseko omnye woxanduva, umthetho kaConway, kunye nendlela yoyilo oluqhutywa yisizinda, emva kweeseshini ezininzi zokuhlasela isiganeko, i-domain yonke yahlulahlulwe yangamacandelo amathathu anemida echaziweyo enemida ecacileyo, iimodeli zesizinda, kunye nolwimi oluhlala kwindawo yonke.
Eyokuqala inikwe umsebenzi wokukhwela nokuqulunqa izicelo ezintsha zemali-mboleko. Inkqubo yesibini ivavanya ezi zicelo kwaye yenza izigqibo ngokusekelwe kwidatha enikeziweyo. Le nkqubo yovavanyo, kuquka i-KYC/KYB, i-antifraud, kunye nokuhlolwa kwengozi yetyala, inokutya ixesha, ifuna amandla okuphatha amawaka ezicelo ngaxeshanye. Ngenxa yoko, oku kusebenza kunikezelwe kwi-microservice ezinikeleyo enedatabase yayo, evumela ukulinganisa okuzimeleyo.
Ngaphaya koko, ezi subsystems zilawulwa ngamaqela amabini ahlukeneyo, ngalinye linemijikelo yalo yokukhululwa, izivumelwano zenqanaba lenkonzo (SLA), kunye neemfuno zokuncipha.
Okokugqibela , kukho inkonzo yesaziso ekhethekileyo yokuthumela izilumkiso kubathengi.
Nantsi inkcazo esulungekileyo yemeko yosetyenziso oluphambili lwesixokelelwano:
Yinkqubo entle nelula kwaye yakudala xa uyijonga kuqala, kodwa makhe sizijule kwindlela inkonzo yesicelo seMali-mboleko ewuqhuba ngayo umyalelo wokungenisa isicelo semali-mboleko.
Sinokuqwalasela iindlela ezimbini zonxibelelwano lwenkonzo:
I-First-Local-Commit-Emva koko-Papasha: Kule ndlela, inkonzo ihlaziya i-database yayo yendawo (izibophelelo) kwaye ipapashe isiganeko okanye umyalezo kwezinye iinkonzo.
I-First-Papash-Ke-Local-Commit: Ngokuchaseneyo, le ndlela ibandakanya ukupapasha isiganeko okanye umyalezo ngaphambi kokuba wenze utshintsho kwisiseko sedatha yendawo.
Zombini ezi ndlela zinemiqobo yazo kwaye azikhuselekanga ngokuyinxenye kunxibelelwano kwiinkqubo ezisasazwayo.
Lo ngumzobo wolandelelwano lokusebenzisa indlela yokuqala.
Kule meko, iNkonzo yeSicelo seMboleko isebenzisa indlela yokuQala-yeNdawo-yeKhomishini-Emva koko-iPapasha , apho iqala ukwenza intengiselwano ize izame ukuthumela isaziso kwenye inkqubo. Nangona kunjalo, le nkqubo inokuthi ingaphumeleli ukuba, ngokomzekelo, kukho imiba yenethiwekhi, iNkonzo yoVavanyo ayifumaneki, okanye iNkonzo yeSicelo seMali mboleko ihlangabezana nephutha lokuphuma kweMemori (OOM) kunye nokuphahlazeka. Kwiimeko ezinjalo, umyalezo uya kulahleka, ushiye uVavanyo ngaphandle kwesaziso sesicelo esitsha semali-mboleko, ngaphandle kokuba kuphunyezwe amanyathelo ongezelelweyo.
Kwaye owesibini.
Kwimeko yokuQala yokuPapasha-Kwaye-kweNdawo , iNkonzo yeSicelo seMali-mboleko ijongene nemingcipheko ebalulekileyo. Inokwazisa iNkonzo yoVavanyo malunga nesicelo esitsha kodwa isilele ukugcina olu hlaziyo ekuhlaleni ngenxa yeengxaki ezinjengemiba yedathabheyisi, iimpazamo zememori, okanye iibhugi zekhowudi. Le ndlela ingakhokelela ekungahambelani okuphawulekayo kwidatha, enokubangela iingxaki ezinzulu, kuxhomekeke kwindlela iNkonzo yokuHlolwa kweMali-mboleko iphatha ngayo izicelo ezingenayo.
Ngoko ke, kufuneka sichonge isisombululo esinika indlela eyomeleleyo yokupapasha iziganeko kubathengi bangaphandle. Kodwa, ngaphambi kokuphonononga izisombululo ezinokuthi zibekho, kufuneka siqale sicacise iintlobo zokuqinisekisa ukuhanjiswa kwemiyalezo ezinokufezekiswa kwiinkqubo ezisasazwayo.
Zine iindidi zeziqinisekiso esinokuziphumeza.
Akukho ziqinisekiso
Akukho siqinisekiso sokuba umyalezo uya kuhanjiswa kwindawo oya kuyo. Indlela yokuQala-Yasekuhlaleni-Zibophelele-Emva koko-Papasha ngokuchanekileyo malunga noku. Abathengi banokufumana imiyalezo kube kanye, amaxesha amaninzi, okanye bangaze kwaphela.
Ukuhanjiswa kwakanye
Kanye xa ukuhanjiswa kuthetha ukuba umyalezo uyakusiwa kwindawo ekuyiwa kuyo uninzi lwexesha eli-1. Indlela ethi First-Local-Commit-En-Publish inokuphunyezwa ngolu hlobo kunye nomgaqo-nkqubo wokuzama kwakhona ngexabiso elinye.
Ubuncinci kube kanye ukuhanjiswa\Abathengi baya kufumana kwaye baqhubeke nomyalezo ngamnye kodwa banokufumana umyalezo ofanayo nangaphezulu.
Kanye kanye unikezelo\ Kanye kanye xa ukuhanjiswa kuthetha ukuba umthengi uya kufumana umyalezo ngokufanelekileyo kube kanye.
Ngobuchwephesha, kuyenzeka ukuba kuphunyezwe ngentengiselwano ye-Kafka kunye nokuphunyezwa kokungenamandla komvelisi kunye nomthengi.
Kwiimeko ezininzi, 'ubuncinci kube kanye' iziqinisekiso zonikezelo zilungisa imiba emininzi ngokuqinisekisa ukuba imiyalezo ihanjiswa kanye, kodwa abathengi kufuneka bangabi namandla. Nangona kunjalo, xa kujongwa ukusilela kothungelwano olungenakuthintelwa, yonke ingqiqo yabathengi kufuneka ingabi namandla ukunqanda ukusetyenzwa kwemiyalezo ephindwe kabini, nokuba zithini na iziqinisekiso zomvelisi. Ke ngoko, le mfuno ayiyongxaki kangako njengoko ibonakalisa ubunyani.
Zininzi izisombululo kule ngxaki, ezineengenelo kunye nezingeloncedo zazo.
Ngokutsho kweWikipedia, iKomidi yeZigaba eziMbini (2PC) yinkqubo yentengiselwano esasazwayo esetyenziswa kwisayensi yekhompyuter kunye neenkqubo zolawulo lwedathabheyisi ukuqinisekisa ukuhambelana kunye nokuthembeka kweentengiselwano ezisasazwayo. Yenzelwe iimeko apho oovimba abaninzi (umzekelo, oovimba beenkcukacha) kufuneka bathathe inxaxheba kwintengiselwano enye, kwaye iqinisekisa ukuba bonke bayayenza itransekshini okanye bonke bayayilahla, ngaloo ndlela igcina ukuhambelana kwedatha. Kuvakala kanye le nto siyifunayo, kodwa iCommit yeZigaba eZimbini inemiqobo emininzi:
Isisombululo esibonakalayo se-microservices architecture kukusebenzisa ipateni (okanye ngamanye amaxesha i-anti-pattern) - i-database ekwabelwana ngayo. Le ndlela inengqiqo kakhulu ukuba ufuna ukuhambelana kwentengiselwano kuzo zonke iitheyibhile ezininzi kwiindawo zogcino-lwazi ezahlukeneyo, sebenzisa nje isiseko sedatha ekwabelwana ngaso kwezi microservices.
Ukungaphumeleli kwale ndlela kubandakanya ukuzisa inqaku elinye lokungaphumeleli, ukuvimbela ukulinganiswa kwedatha ezimeleyo, kunye nokunciphisa amandla okusebenzisa izisombululo zesiseko sedatha ezifanelekileyo ngokufanelekileyo kwiimfuno ezithile kunye namatyala okusebenzisa. Ukongeza, uhlengahlengiso kwiikhowudi ze-microservices kuya kuba yimfuneko ukuxhasa uhlobo olunjalo lokuthengiselana.
' Ibhokisi yangaphandle yetransekshini ' yipatheni yoyilo esetyenziswa kwiisistim ezisasaziweyo ukuqinisekisa ukusasazwa komyalezo othembekileyo, naphezu kweenkqubo zomyalezo ezingathembekanga. Ibandakanya ukugcina imisitho kwitheyibhile ekhethiweyo ye-'OutboxEvents' ngaphakathi kwentengiselwano efanayo nomsebenzi ngokwawo. Le ndlela ihambelana kakuhle neempawu ze-ACID zolwazi olunxulumeneyo. Ngokwahlukileyo, uninzi lweenkcukacha ze-No-SQL azixhasi ngokupheleleyo iipropathi ze-ACID, zikhetha endaweni yemigaqo ye-CAP theorem kunye nefilosofi ye-BASE, ebeka phambili ukufumaneka kunye nokuhambelana ekugqibeleni ngaphezu kokuhambelana okungqongqo.
Ibhokisi yangaphandle yetransekshini ibonelela nokuba kanye isiqinisekiso kwaye inokuphunyezwa ngeendlela ezininzi:
Ukuhanjiswa kwelog yentengiselwano
Umpapashi wovoto
Indlela yokufaka umsila wentengiselwano ithetha ukusebenzisa izisombululo ezithe ngqo zedatha efana neCDC (Tshintsha iDatha yokuThatha). Iintsilelo eziphambili zaloo ndlela zezi:
Izisombululo ezithile zeDatabase
Ukunyuka kwexesha lokulinda ngenxa yeenkcukacha zokuphunyezwa kweCDC
Enye indlela yi- Polling Publisher , eququzelela ukhuphelo lwe-outbox ngokuvota kwitheyibhile ye-outbox. I-drawback ephambili yale ndlela yindlela yokwandisa umthwalo wedatha, nto leyo inokukhokelela kwiindleko eziphezulu. Ngaphaya koko, ayizizo zonke iinkcukacha ze-No-SQL ezixhasa imibuzo esebenzayo kumacandelo athile amaxwebhu. Ukutsala amaxwebhu ewonke, ke ngoko, kunokukhokelela ekuthotyweni kwentsebenzo.
Nanku umzobo omncinci wolandelelwano ochaza indlela esebenza ngayo.
Owona mceli mngeni uphambili ngepatheni yeNtengiselwano yee-Awuthbhoks ikukuxhomekeka kwayo kwiipropati ze-ACID zedatha. Inokuba ngokuthe ngqo kuluhlu lwedatha ye-OLTP kodwa ibeka imingeni kwindawo ye-NoSQL. Ukulungisa oku, isisombululo esinokubakho kukusebenzisa ilog yesihlomelo (umzekelo, iKafka) ukusuka ekuqaliseni ukusetyenzwa kwesicelo.
Endaweni yokulungisa ngokuthe ngqo umyalelo 'wokungenisa isicelo semali-mboleko', siwuthumela ngoko nangoko kwisihloko sangaphakathi se-Kafka kwaye emva koko sibuyisele isiphumo 'esamkelweyo' kumxhasi. Nangona kunjalo, kuba kunokwenzeka ukuba umyalelo usafuna ukuqwalaselwa, asikwazi ukwazisa umthengi ngokukhawuleza ngesiphumo. Ukulawula oku kungaguquguquki, sinokusebenzisa ubuchule obunje ngokuvota okude, uvoto oluqalwe ngabathengi, uhlaziyo lwe-UI olunethemba, okanye ukusebenzisa iWebSockets okanye iServer-Sent Events kwizaziso. Nangona kunjalo, esi sisihloko esahlukileyo ngokupheleleyo, ngoko ke masibuyele kumxholo wethu wokuqala.
Sithumele umyalezo kwisihloko sangaphakathi seKafka. INkonzo yeSicelo seMali-mboleko ke iwusebenzisa lo myalezo - umyalelo ofanayo owufumene kumxhasi - kwaye iqala ukuqhubekeka. Okokuqala, yenza ingqiqo yeshishini; kuphela emva kokuba le ngqiqo yenziwe ngempumelelo kwaye iziphumo ziyaqhubeka, ipapasha imiyalezo emitsha kwisihloko sikawonkewonke seKafka.
Makhe sijonge isuntswana lekhowudi-pseudo.
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(); }
Kuthekani ukuba ukusetyenzwa kwengqiqo yeshishini kuyasilela? Akukho maxhala, kuba i-offset ayikenziwa, umyalezo uza kuphinda uzame kwakhona.
Kuthekani ukuba ukuthumela iminyhadala emitsha eKafka kusilele? Akukho maxhala, kuba ingqiqo yeshishini ayinamsebenzi, ayizukudala isicelo semali-mboleko ephindiweyo. Endaweni yoko, iya kuzama ukuthumela imiyalezo kwakhona kwisihloko seKafka yoluntu.
Kuthekani ukuba imiyalezo ithunyelwa eKafka, kodwa isibophelelo sokuhlawula asiphumelelanga? Akukho maxhala, kuba ingqiqo yeshishini ingenamsebenzi, ayizukudala isicelo semali-mboleko ephindiweyo. Endaweni yoko, iya kuthumela imiyalezo kwisihloko sikaKafka sikawonke-wonke kwaye sinethemba lokuba ukuzibophelela kwe-offset kuyaphumelela ngeli xesha.
Iintsilelo eziphambili zale ndlela ziquka ukuntsonkotha okongeziweyo okunxulunyaniswa nesimbo esitsha senkqubo, ukungaguquguquki ekugqibeleni (ekubeni umxhasi engayi kusazi ngoko nangoko isiphumo), kunye nemfuno yokuba yonke ingqiqo yeshishini ingabi namandla.
Yintoni ukukhangela imisitho, yaye inokusetyenziswa njani apha? Ukufumana umsitho yipatheni yoyilo lwesoftware esetyenziselwa ukulinganisa imeko yenkqubo ngokufaka zonke iinguqu kwidatha yayo njengothotho lweziganeko ezingenakuguquleka. Ezi ziganeko zimele iinyani okanye iinguqu zelizwe kwaye zisebenza njengomthombo omnye wenyaniso kwimeko yangoku yenkqubo. Ngoko, ngokobuchwephesha, ngokuphumeza inkqubo yokukhangela isiganeko, sele sinazo zonke iziganeko kwi-EventStore, kwaye le EventStore ingasetyenziswa ngabathengi njengomthombo omnye wenyaniso malunga nento eyenzekayo. Akukho mfuneko yesisombululo esithile sesiseko sokulandelela zonke iinguqu okanye iinkxalabo malunga noku-odola, ingxaki kuphela ihleli kwicala lokufunda ukususela ekubeni ikwazi ukufumana imeko yokwenyani yequmrhu kufuneka iphinde idlale zonke iziganeko.
Kweli nqaku, sihlolisise iindlela ezininzi zokwakha imiyalezo ethembekileyo kwiinkqubo ezisasazwayo. Kukho iingcebiso ezininzi esinokuziqwalasela ngelixa sisakha iinkqubo ezinezi mpawu
Kwixesha elizayo, siza kujonga umzekelo osebenzayo wokuphumeza i-Transactional Outbox. 'Yabona
wena!