![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Ukwakha uhlelo oluthembekile, olutholakala kakhulu, olusabalaliswa kalula ludinga ukubambelela kumasu athile, izimiso, namaphethini. Ukwakhiwa kwezinhlelo ezinjalo kubandakanya ukubhekana nenqwaba yezinselelo. Phakathi kwezindaba ezivame kakhulu neziyisisekelo inkinga yokubhala okukabili .
"Inkinga yokubhala okukabili" inselele evela ezinhlelweni ezisabalalisiwe, ikakhulukazi lapho kukhulunywa ngemithombo yedatha eminingi noma izizindalwazi ezidinga ukugcinwa ekuvunyelanisweni. Kubhekisela ebunzimeni bokuqinisekisa ukuthi izinguquko zedatha zibhalwa ngokungaguquki ezitolo zedatha ezihlukahlukene, njengezigcinilwazi noma izinqolobane, ngaphandle kokwethula izinkinga ezifana nokungahambisani kwedatha, ukungqubuzana, noma izithiyo zokusebenza.
I-microservices architecture kanye nesizindalwazi sephethini ngesevisi ngayinye ikulethela izinzuzo eziningi, njengokuthunyelwa okuzimele nokukala, ukwehluleka okukodwa, kanye nokukhushulwa okungenzeka kwesivinini sokuthuthukiswa. Kodwa-ke, ukusebenza kudinga izinguquko phakathi kwama-microservices amaningi, okukuphoqa ukuthi ucabange ngesixazululo esithembekile sokubhekana nale nkinga.
Ake sicabangele isimo lapho isizinda sethu sibandakanya ukwamukela izicelo zemalimboleko, sizihlole, bese sithumela izaziso zesaziso kumakhasimende.
Ngokomoya wesimiso esinomthwalo wemfanelo owodwa, umthetho ka-Conway, kanye nendlela yokuklama eqhutshwa isizinda, ngemva kwezikhathi ezimbalwa zokuhlasela izenzakalo, sonke isizinda sahlukaniswa saba izizindana ezingaphansi ezintathu ezinomongo onqunyelwe ochaziwe onemingcele ecacile, amamodeli wesizinda, nolimi olutholakala yonke indawo.
Esokuqala sinikezwe umsebenzi wokugibela kanye nokuhlanganisa izicelo ezintsha zokubolekwa imali. Uhlelo lwesibili luhlola lezi zinhlelo zokusebenza bese lwenza izinqumo ngokusekelwe kudatha enikeziwe. Le nqubo yokuhlola, ehlanganisa i-KYC/KYB, ukuvimbela ukukhwabanisa, nokuhlolwa kwengozi yesikweletu, kungase kudle isikhathi, okudinge ikhono lokusingatha izinkulungwane zezicelo ngesikhathi esisodwa. Ngenxa yalokho, lokhu kusebenza kudluliselwe ku-microservice ezinikele enesizindalwazi sayo, okuvumela ukukala okuzimele.
Ngaphezu kwalokho, lawa masistimu angaphansi aphethwe amaqembu amabili ahlukene, ngalinye linemijikelezo yalo yokukhishwa, izivumelwano zeleveli yesevisi (i-SLA), kanye nezidingo zokukala.
Okokugcina , isevisi yesaziso esikhethekile isikhona ukuthumela izaziso kumakhasimende.
Nansi incazelo ethuthukisiwe yesimo esiyinhloko sokusetshenziswa kwesistimu:
Iwuhlelo olulula kakhulu futhi lwakudala uma uthi nhlá, kodwa ake singene siqonde ukuthi isevisi yesicelo seMalimboleko iwucubungula kanjani umyalo wokufaka isicelo semalimboleko.
Singacabangela izindlela ezimbili zokusebenzisana kwesevisi:
I-First-Local-Commit-Then-Publish: Ngale ndlela, isevisi ibuyekeza isizindalwazi sayo sendawo (iyazibophezela) bese ishicilela umcimbi noma umlayezo kwezinye izinkonzo.
I-First-Publish-Then-Local-Commit: Ngokuphambene, le ndlela ihlanganisa ukushicilela umcimbi noma umlayezo ngaphambi kokwenza izinguquko kusizindalwazi sendawo.
Zombili izindlela zinezihibe zazo futhi aziphephile kancane ekuxhumaneni ezinhlelweni ezisabalalisiwe.
Lona umdwebo wokulandelana wokusebenzisa indlela yokuqala.
Kulesi simo, Isevisi Yesicelo Semali Ebolekiwe isebenzisa indlela YokuQala-Kwasendaweni-Izibophezele-Bese-Ishicilele , lapho iqala khona ukwenza umsebenzi bese izama ukuthumela isaziso kwenye isistimu. Kodwa-ke, le nqubo ingase yehluleke uma, ngokwesibonelo, kunezinkinga zenethiwekhi, Isevisi Yokuhlola ingatholakali, noma Isevisi Yesicelo Semalimboleko ihlangabezana nephutha lokuphuma kweMemori (OOM) nokuphahlazeka. Ezimweni ezinjalo, umlayezo uzolahleka, kushiye Ukuhlola ngaphandle kwesaziso sesicelo esisha semalimboleko, ngaphandle kwalapho kuqaliswa izinyathelo ezengeziwe.
Neyesibili.
Esimweni Sokushicilelwa Kokuqala Kwase-ke-sendawo , Isevisi Yesicelo Semalimboleko ibhekene nezingozi ezinkulu kakhulu. Ingase yazise Isevisi Yokuhlola mayelana nohlelo lokusebenza olusha kodwa yehluleke ukulondoloza lesi sibuyekezo endaweni ngenxa yezinkinga ezifana nezinkinga zesizindalwazi, amaphutha enkumbulo, noma iziphazamisi zekhodi. Le ndlela ingaholela ekushintshaneni okuphawulekayo kwedatha, okungase kubangele izinkinga ezinkulu, kuye ngokuthi Isevisi Yokubuyekeza Imalimboleko iziphatha kanjani izinhlelo zokusebenza ezingenayo.
Ngakho-ke, kufanele sihlonze isisombululo esinikeza indlela eqinile yokushicilela imicimbi kubathengi bangaphandle. Kodwa, ngaphambi kokungena ezisombululweni ezingaba khona, kufanele siqale sicacise izinhlobo zeziqinisekiso zokulethwa kwemiyalezo ezingafinyeleleka kumasistimu asabalalisiwe.
Kunezinhlobo ezine zeziqinisekiso esingazithola.
Azikho iziqinisekiso
Asikho isiqinisekiso sokuthi umlayezo uzolethwa endaweni oya kuyo. Indlela ethi First-Local-Commit-Then-Publish imayelana nalokhu. Abathengi bangase bathole imilayezo kanye, izikhathi eziningi, noma bangalokothi bathole nhlobo.
Ukulethwa kanye nje
Ukulethwa kanye nje kusho ukuthi umlayezo uzolethwa endaweni okungenani isikhathi esingu-1. Indlela ethi First-Local-Commit-Then-Publish ingasetshenziswa ngale ndlela kanye nenqubomgomo yokuzama kabusha yemizamo enevelu yokuqala.
Okungenani kanye uma kulethwa\Abathengi bazothola futhi bacubungule yonke imilayezo kodwa bangathola umlayezo ofanayo izikhathi ezingaphezu kwesisodwa.
Ukulethwa kanye kanye\Kanye kanye ukulethwa kusho ukuthi umthengi uzothola umlayezo ngempumelelo kanye.
Ngobuchwepheshe, kuyenzeka ukuthi kuzuzwe nge-Kafka transactions kanye nokusetshenziswa okuqondile komkhiqizi nomthengi.
Ezimweni eziningi, iziqinisekiso zokulethwa 'okungenani kanye' zibhekana nezinkinga eziningi ngokuqinisekisa ukuthi imilayezo ilethwa okungenani kanye, kodwa abathengi kufanele bangabi namandla. Kodwa-ke, uma kubhekwa ukwehluleka kwenethiwekhi okungagwemeki, yonke ingqondo yomthengi kufanele ingabi namandla ukugwema ukucubungula imilayezo eyimpinda, kungakhathaliseki iziqinisekiso zomkhiqizi. Ngakho-ke, le mfuneko ayikona ukuhlehla kangako njengoba ibonisa iqiniso.
Kunenqwaba yezixazululo zale nkinga, ezinezinzuzo kanye nokubi.
Ngokuvumelana ne Wikipedia, i-Two-Phase Commit (2PC) iyiphrothokholi yokuthengiselana esabalalisiwe esetshenziswa kusayensi yekhompiyutha kanye nezinhlelo zokuphatha isizindalwazi ukuze kuqinisekiswe ukuvumelana nokuthembeka kokuthengiselana okusabalalisiwe. Idizayinelwe izimo lapho izinsiza eziningi (isb., izizindalwazi) zidinga ukubamba iqhaza kumsebenzi owodwa, futhi iqinisekisa ukuthi zonke ziyawenza okwenziwayo noma zonke ziyayichitha, ngaleyo ndlela igcine ukufana kwedatha. Kuzwakala impela esikudingayo, kepha i-Two-Phase Commit inezinkinga ezimbalwa:
Isixazululo esibonakala kakhulu se-microservices architecture ukusebenzisa iphethini (noma ngezinye izikhathi i-anti-pattern) - isizindalwazi esabiwe. Le ndlela inembile kakhulu uma udinga ukuvumelana kokwenzekayo kuwo wonke amathebula amaningi kuzinqolobane ezihlukene, vele usebenzise isizindalwazi esisodwa esabiwe salezi zinsiza ezincane.
Izithiyo zale ndlela zihlanganisa ukwethulwa kwephuzu elilodwa lokwehluleka, ukuvimbela ukukalwa kwedatha egciniwe okuzimele, kanye nokunciphisa ikhono lokusebenzisa izixazululo zedathabhesi ehlukene ezifaneleka kakhulu izidingo ezithile kanye namacala okusetshenziswa. Ukwengeza, ukuguqulwa kuma-codebases we-microservices kungadingeka ukuze kusekelwe uhlobo olunjalo lomsebenzi osabalalisiwe.
' Ibhokisi lokuphumayo lokuthengiselana ' liyiphethini yokuklama esetshenziswa ezinhlelweni ezisabalalisiwe ukuze kuqinisekiswe ukusatshalaliswa komlayezo okuthembekile, ngisho nalapho kubhekene nezinhlelo zemiyalezo ezingathembekile. Kubandakanya ukugcina imicimbi kuthebula elikhethiwe le-'OutboxEvents' phakathi komsebenzi ofanayo nomsebenzi ngokwawo. Le ndlela ihambisana kahle nezakhiwo ze-ACID zolwazi olugciniwe. Ngokuphambene, imininingwane eminingi ye-No-SQL ayisekeli ngokugcwele izakhiwo ze-ACID, esikhundleni salokho ikhetha imigomo ye-CAP theorem nefilosofi ye-BASE, ebeka phambili ukutholakala nokuvumelana ekugcineni kunokuvumelana okuqinile.
Ibhokisi lokuphumayo lokwenziwayo linikeza isiqinisekiso okungenani kanye futhi lingasetshenziswa ngezindlela ezimbalwa:
Umsila welogi yokwenziwe
Umshicileli wokuvota
Indlela yokulandelanisa ilogu yokwenziwayo isho ukusebenzisa izixazululo eziqondene nesizindalwazi ezifana ne-CDC (Shintsha Ukuthwebula Kwedatha). Izithiyo eziyinhloko zaleyo ndlela yilezi:
Izixazululo eziqondene nesizindalwazi
Ukubambezeleka okukhulisiwe ngenxa yemininingwane ethile yokusetshenziswa kwe-CDC
Enye indlela I- Polling Publisher , esiza ukulayishwa kwebhokisi lokuphumayo ngokuvotela ithebula lebhokisi lokuphumayo. I-drawback eyinhloko yale ndlela yikhono lokwenyuka komthwalo we-database, okungaholela ezindlekweni eziphezulu. Ngaphezu kwalokho, akuzona zonke izizindalwazi ze-No-SQL ezisekela imibuzo ephumelelayo yezingxenye ezithile zedokhumenti. Ngakho-ke, ukukhipha wonke amadokhumenti kungaholela ekwehleni kokusebenza.
Nawu umdwebo omncane wokulandelana ochaza ukuthi usebenza kanjani.
Inselele enkulu ngephethini Yebhokisi Lemilayezo Ephumayo Yokwenziwayo ilele ekuncikeni kwayo kusizindalwazi sezakhiwo ze-ACID. Ingahle iqonde kusizindalwazi esijwayelekile se-OLTP kodwa ilethe izinselelo endaweni ye-NoSQL. Ukuze kubhekwane nalokhu, isixazululo esingaba khona ukusebenzisa ilogi yesithasiselo (ngokwesibonelo, i-Kafka) kusukela ekuqaliseni ukucutshungulwa kwesicelo.
Esikhundleni sokucubungula ngokuqondile umyalo 'wokuhambisa isicelo semalimboleko', siwuthumela ngokushesha esihlokweni sangaphakathi se-Kafka bese sibuyisela umphumela 'owamukelwe' kuklayenti. Nokho, njengoba kungenzeka kakhulu ukuthi umyalo usadinga ukucutshungulwa, asikwazi ukwazisa ikhasimende ngokushesha ngomphumela. Ukuze silawule lokhu kuvumelana ekugcineni, singasebenzisa amasu afana nokuvota okude, ukuvota okuqalwe yiklayenti, ukubuyekezwa kwe-UI okunethemba, noma ukusebenzisa i-WebSockets noma Imicimbi Ethunyelwe Ngeseva ukuze uthole izaziso. Nokho, lesi yisihloko esihluke ngokuphelele, ngakho-ke ake sibuyele esihlokweni sethu sokuqala.
Sithumele umlayezo ngesihloko sangaphakathi se-Kafka. Isevisi Yesicelo Semali Ebolekiwe ibe isisebenzisa lo mlayezo - umyalo ofanayo ewuthole kuklayenti - bese iqala ukucutshungulwa. Okokuqala, yenza umqondo othile webhizinisi; kuphela ngemva kokuba le logic isetshenziswe ngempumelelo futhi imiphumela iphikelela, ishicilela imilayezo emisha esihlokweni sasesidlangalaleni se-Kafka.
Ake sibheke i-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(); }
Kuthiwani uma ukucutshungulwa komqondo webhizinisi kwehluleka? Azikho izinkathazo, njengoba i-offset ingakenziwa, umlayezo uzozanywa futhi.
Kuthiwani uma ukuthumela imicimbi emisha e-Kafka kwehluleka? Azikho izinkathazo, njengoba ingqondo yebhizinisi ingenangqondo, ngeke idale isicelo semalimboleko esiyimpinda. Kunalokho, izozama ukuthumela kabusha imilayezo esihlokweni esisesidlangalaleni se-Kafka.
Kuthiwani uma imilayezo ithunyelwa e-Kafka, kodwa isivumelwano se-offset sihluleka? Azikho izinkathazo, njengoba ingqondo yebhizinisi ingenangqondo, ngeke idale isicelo semalimboleko esiyimpinda. Kunalokho, izothumela imilayezo esihlokweni esisesidlangalaleni se-Kafka futhi sithemba ukuthi ukuzibophezela kwe-offset kuzophumelela kulokhu.
Izithiyo eziyinhloko zale ndlela zihlanganisa inkimbinkimbi eyengeziwe ehlotshaniswa nesitayela esisha sokuhlela, ukungaguquguquki ekugcineni (njengoba iklayenti ngeke liwazi umphumela ngokushesha), kanye nemfuneko yokuthi wonke umqondo webhizinisi ungabi namandla.
Kuyini ukuthola umcimbi, futhi ungasetshenziswa kanjani lapha? Ukuthola umcimbi iphethini yezakhiwo zesofthiwe esetshenziselwa ukumodela isimo sesistimu ngokuthwebula zonke izinguquko kudatha yayo njengochungechunge lwemicimbi engaguquleki. Lezi zenzakalo zimelela amaqiniso noma izinguquko zesimo futhi zisebenza njengomthombo owodwa weqiniso wesimo samanje sesistimu. Ngakho-ke, ngokobuchwepheshe, ngokusebenzisa uhlelo lokuthola umcimbi, sesivele sinayo yonke imicimbi ku-EventStore, futhi le EventStore ingasetshenziswa abathengi njengomthombo owodwa weqiniso mayelana nokwenzekile. Asikho isidingo sesixazululo sesizindalwazi esithile sokulandelela zonke izinguquko noma ukukhathazeka mayelana noku-oda, inkinga kuphela ihlezi ohlangothini lokufunda kusukela ukuze ukwazi ukuthola isimo sangempela sebhizinisi siyadingeka ukuze udlale kabusha yonke imicimbi.
Kulesi sihloko, sibuyekeze izindlela ezimbalwa zokwakha imiyalezo ethembekile kumasistimu asabalalisiwe. Kunezincomo ezimbalwa esingase sizicabange ngenkathi sakha amasistimu analezi zici
Ngokuzayo, sizobheka isibonelo esisebenza kakhulu sokuqalisa Ibhokisi Lemilayezo Ephumayo Yokwenziwayo. Bheka
wena!