0% found this document useful (0 votes)
22 views32 pages

System Design

Uploaded by

26mohit102002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
22 views32 pages

System Design

Uploaded by

26mohit102002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
I 1): |Txy r0_bxeak -the problem into simplex Modules - | (Top down approach _) 2): Talk about the trade - Offs. CNo solution is perfect) _ [Calculated based on all tthe consfyaints and +ne end test cases Ask uestions « Consteainfs | & Punctionaltty inding _& | Requliement’s ) laddvessin9 bottlenecks TRatlonalize ideas and inputs e Aychitectural Pieces / yesources avatiable © How these wesources work +o9ethey. © Utilization & Thade off. | lion Cz i in CAP THeovem toad balancing Queues Cachin Replication SQtL_vsNo- SAL Indexes Proxies Data Paxtitioning . C Distributed system) evi os (eum Random: = i Round = xObin — Random ( weignts Fox _____mMemoty & cpu cycles) Mo utilize Fu Scalability & ¥edundancy , add 218. ue 1) User EBL» Web server 2) |Web SewergebB2 , App Sever / cache cower (Intemai larform. 3: \Tnpesnal platform -B3 _. pe Tdke a pool of sewvices hosts & balance load —_—? detect hosts thet ave not xesponsible __— |\yecovered hosts ree ais 9 —> |addition of new hosts : nie a Load balancing Func ctlonaiity 1D Ds (Cache e Services ) ang # Artractive Solution for developers. (Small scale system) _ LAs System a —> LBs ( Standalone Sewers). “Expensive but high Setanta 2-9. Citrix Netscaley | Not trivial tp Configure eng Large Companies tend to avoid tnis_ Contig. OX use it as 4 peint oF contact to thely Syste: jtoSeWwve _usey request & Thtva network uses | | smart clients/ hybrid Soiution = eee | Fox load balancing tvaefic. = pz: No cost of purchasing dedicated Hardwase. hybrid approach. ,_=P_OSS Load balancess H : (CLocatly bound pox 2-9. localhost: 9900 ; = manage. d_by HAPyoxy i FFicient management | i of vequest on the port) — Running, on intermediate server. | Peoxies yunning, between different sexvey side iCcomponents Manages health checks temoval & addition of machines balances vequests alc pools. er ASTES Structured je] Unstructured Predefined schema je | distyibuted Data, in vows £crJumn| lel dynamic Schema Row > One Entity Info _ Column => Sepasare "dara points key-value stoses on __[= Document DB = My 5aoeee wide-(olumn 08 Ovacle Ms SAL Sexver S@vite Postases MariaDB > array OF key -Value poly Key > attribute Oe inked to Dara whose xelati Ons axe best sepr4 =sented in Graphs 2 Nodes (Entities) > Lines Cconnection CInstead of tables, Columns, Families. _ alo need of know oF columns Analysis of large datasets. el difference: een SG NoSB.L Nos@t Tables CRow — Entity, Column Data Ons . a ette 1). | You need to ensure ACID Compliance + AcID_ Compliance => Reduces anomalies => Protects Intigrity of the database. || Fox many & - Commerce & Financlal_application —__ ACID Complaint DB is the_ Eivst choice. saireeies _2). | Your _data_is structused & unchanging. TP your business. is not’ experiencing vapid aQxouth evo sudden changes= = ess __ =D_No_vequivements of mote Sexvers ._ | => _data_is consistent. | then there's no yeason_to_use System Desian _| +0 Support vasiety of data £ high tvaftic._ BTL Koma! When all other Components of system aye fast | quan lae _& seayching for data > bottleneck. NoS&L prevent data from being bottleneck. ____| Big data => large Success for nlos@l. 1). Tb * stove jarge volumes of data (1ittle | no ; Styucture) No Umit on type of data. aor we |Document DB => Stoves all data in One place _| C No need of type of data) } 2) Using cloud & storage to -the fullest . [excellent cost coving solution. Easy spsead oF | data acyoss multiple Sexvers to Scale up). (OR commodity b/w on site Caffoxdable, smaiier) (=> No headache of additional s/v . |& Noger DBs like cassandra > designed +o Scale acyoss multiple data centers our 8 eo ies). |Usefur_ Fox xapid | agile development. TF you've makin ick Ttevattons on down. iby updating [Consistency] ( Ail nodes see same several nodes before _data_at same time) allowing xeads — Ne, . %. ty ya, COUChDB) & |Evety sequest ets yesponse : .4 \Csuccess/ Failure) System continues to work despite ___ message loss/ partial BQol\ures a 9. Achieved by replicating ¢ can_ sustain any data across diffexent amount of nemotk Sexvess Failure without vesuiting in Foiluse of entive network. ) Data is sufficiently, xeplicated across combination of nodes Networks to Keep the System up. Th is impossible fora distributed system to i oo +tto_oF ite cannot_build-a da tastoxe which is : > Continually available mi - | Sequenti ally Consistent : gut women Lantern) ieee FoSluve tolerant. E Because , To be Consistent =S> all nodes should see the Same set of updates in -the I Same order. _ ‘But i€ network suffers Partition, updote in one partition might not make it to other partitions. G chient reads data From out-of-date partition After having xead up-to-date _ vHton + Sclution, Stop serving vequests yom out-of-date artiton - e : > Service is no longer LOO. available. |Duplication of critical data & Sexvices . incseasing yeliability of system. |Pox critical services Ye data => ensure that multiple icopies] versions axe yunning stmulpaneously on _ different Sewers | databases. | => Secuxe against single node Failures. i Psovides backups if needed in cyisi Failover a4 i ‘ es Server Secondary Sesves. __ =— oe i a — = = Active dato cf > mma : HE Sewice Redundancy? Shaved - nothing, | architecture . Every node > Independent. nlo centyal sevice | __________ Managing state. | More resilient +o Follures a New Servers <— Helps In addition Without Scalavility, A single points - condiHons of Failuge hee |Lead balancing > Scales horizontally [Caching ? Locality of refetence principle & used tn almost every layer of computing Le cation Server cache : Placing a cache divectty on a yeqiest layex node- & Loca! nr of f ceapente Request | ter es ee =| ae Z iE hit. te | ree cae ie missie . sesponse data nodes loca disk. ___( faster than going to_network storage) LB distvibutes request yandoml| Same sequest => cieferent nodes More cache nuiss 2 2 )._ | Global caches 2). | Distvibuted caches Ora 1-2 size eee Divided using, consistent_hasting function sesult ___in Fast tetvieval oF data CRE oT Quex ttt Easy to Incvease cache space by adding Mote nodes. __ ~ ‘ te 4 Disadvantages : ‘Ixesolving a missing node . stasting multiple copies of «can be data on different nodes. handled by Were making tt more I a complicated - art: Even if node disappears = xequest can pull data from Origin. ecu —_ | Single cache space foy all the nodes. Adding a cache sewers / File store ( Faster -than Original store ) AE | DiFficult to manage if no Clients f request incteases - A BS — ve Fixed dataset that needs +0 be cached Special Hw => Past 1/0 Database cache ih to bring ne ——d ata -from-database- _ Contain hot data sets. __ Database | Application I logic undeystands the styategy | hot spots better than cathe. 5 istyibution Ca Stove Fox Sites -that seyves lavge amount of stahc medio e Back-end TF not avaljable bSeNEs TF the site isn't layge enough to have Its own _ CDN. For better & easy Futuse tyansition. | .... Is Wwe static media _using separte subdomain. | Static. [Link] 7 Using lightweight Ngl\nx Serer | cutover DNS From your server TO CDN later. u __ HE Cached data Needs to be Caherent wlth the i a datobosci meme ey i UIP data in p& modified > invalidate the cache Data ts written same time in both Cache 2 DB Lt Complete data consistency € cache = D8) _ ++ Poult tolerance tn case of failure C1 data los i— high latency in writes > 2 write operations: + No cache | for wirrites — yead er re for ee wiitten data > Miss higher Ene 8). rite back cache: [Cache] I Roa "after same taterval “yesponse i client ey under same specified — conditions data is wisitten +e DB F¥OmM Cache - + tow latency % high +threughout fox waite - intensive application . = Data toss 1 Conly one copy tn cache) 4e = Cache Eviction Policies EIFO igo ov FILO | Leu MRU LEU [Data Partitioning, « Splitting up De/table across Multiple machines > manageability , performance, availability Fe LB i We Acrex a certain scale point, it is cheaper and more feasible to scale horizontally by adding more Machines instead of Vertical Scaling by adding buffers Services. Methods of Pastitionin i 1)- Horizontal Partitioning : Different sows lato dife. sis eeecoblese “Sy = Sie s Range based shayding = Storing location | Oble 1: Zip Table2: Zip with > 106000 and soon. zi i ~ different yanges Pine Indie feyent — +abes. x Cons: if tne value of the vange not chosen carefully => leads to Unbalanced seyvers, |_e-9-Table 1 can have move data than table2. | : at | Featuve yilse distyibution of data. Ly in different sevvers . oes eg: = Sevvevt: user info _| i DR Server 2: fpilowess IDB Seves.s : uifehotoss Straightforward +o implement | 1OW impact on app. iF Appradditeonal growth Need +0 Partition Featuse specific DB across various Sexvers- (e-9. tt would not be possible Fora cingie sexver to handle all_ metadata quaries for 10 miilion Phetos by 140 millions users. A loosely coupled approach to work axound Issues _mentoned in above two paytittonings. Cieate lookup sewices =P current partitioning kcheme & abstyacts it away, from -the DB access code. Mapping Ctuple key — DB Sexver ) Easy +0 add DB sewers O% change paytitioning Scheme. Key ov Hash based Parti oning * key atty. oF 5} Hash function Partiton te data number ae Effectively Fixes the -total number of sexvers / | Partition *, = | So tf we add new server | pastition Change In hash functton downtime because of sedistsi bution . tH, List axtitioning : Each Partition 1s assigned a ist of values . —> tore the vecord (Partition based on Round Retin Farttoning : uniform data distsibution - with | n_’ partitions >the‘ |? tuple ts assigned to Partition (1 moa n _ Composite ‘astitioning : Combination of above vtitioning schemes Hashing + List => Consistent Hashing Hash veduces the Ixey space to a size that can be listed._ = |Common Problems of Shayding * Shayded DB: Extya Constraints on -the different operations Operations acvoss multiple tables ox multiple yows in the same “table - No longer yunning in : ___Single_ server. 1): Joins £& Denoxmalization t Joins en tables on Single server? Styeignt __ t! hh ___ forward. * not possible +0 pevform jeins on standard +tables & Less efficient (data need 40 be compiled 7 ______fiom_multiple sewers) FE Workaround > Denoymatize the DB. So that -the quarsies -that previously yeqd- jolns can be performed from a single -tabie- Cons: Perils oF denormalization. data incensistency- ‘Referential Integrity : foreign Keys on Sharded D8. | AlFfeult. * Most of the RDBMS does not support foreign Keys on Sharded DB. ae TF app” demands veFevential integrity on, Sharded DB. | > enforce It In svat a C sau jobs | 40 clean up dangiing yeference)- 5 3) | ‘Rebatancing id ‘Reasons +o change Shayding scheme : a): | non-uniform distribution Cdata Wise) b)- Inon- uniform load balancing (request wise) Woykayound +_1):|Add new OR 2) | yebalanw © Change in partitioning scheme = data movement. G downtime. We can use Gixecty — based partitioning, > hignty complex in & Single polnt oF Fallure Clookup service | pyul pen =? Well Known because of database. => Impzoves Panter to whne yaw > [Create different views of the same datn & Vesy quod for Fitering| sorting of large data sets. Gino need to create additional copies. Using Fox datasets Ge in Size) & Smau payload Spyead over Several saat C ks). Physical devices. — > we need some way +o Find the correct physical location. j-e- [ Peoetes > user under high load situations. if we have limited Caching - L, batthes several requests {nto one. Servey Proxy : Server Filters request log yequests [Cache | y. add/remove headers Freqyentiy used encryption /deayption yesources., Compresston. vequest co-ordination Crequest rat ic Optimization ) eee 4 We can a)so use @— Collapse same dataaccess Spottal locality sequest Into_one- & Collapsing vequest > Collapsed Forwarding fox data -that is Sprtially cluse. Minimize veads From Oxioin- > Effectively manages xequests In_laxqe-scale distributed system. => In Small system —9 pyifes ove Fast > Tn Compiex system —? high incoming load. &individual vurites take ue morte time. * Te achieve high performance & anol lala ltty Ly sustem needs to be asynchymeus ueue de Synchsmaus behaviour —> degrades performance aigPicutt For forx can reees Co scid LZ batancin9 distribution. FE | Queues » asynchrmaus Communication protoco). Client sends task & get Ack Fromqpeue Geceipt) Server as sefrenus for the wesults In Future . Ciient continues Hs work. 3 Limit on-the ize of xequest % number of xequests tn Queue SE (COQueue + Provides fouit totevane. ‘ ____& Protection From _cowice Outage / failure. highly yequest —_ bes 7 yotru fo! luye service yequest Enfo: yvices, qurantee (Dees NOT expose clients outage) ZE (Queues. distyibuted Communication b& Open Sousce \mplementatin. Ly RabbitmM@, Zerom@, active, Beanstak D- Distributed fash -pables Index = hash - Function (key) — aE Suppose were designing distvibuted caching - system wlth n cache serulces G hash- Function > (key tn ) Dyawbacks : 1): NOT horizentaily scalable L> addition of new sewers yesults In Ls needs +0 change all existing, mopping, - : Cdowntime of system ) 2). N6T load balanced _ ee _( becouse of non - uni distribution of data) — Some caches: hat 2 satwated __other caches : idle @ empty °_ Hom to tackle above pyublems? — ea isten hi a ao ¢ What is consistent_tHashing ? > \ery useful stvateqy for distvibuted caching &~ DHTs. ae ee > Minimi eorganization jn scaling up| down. __ only Keys needs to be yemapped . K= tora numbers of Keys N= number of Sewers Pre © | How it works? fe. = "D*. ls ‘Removing Server ‘A’ willl yesult in moving -the ‘Key-)' to 8’, 255.40 hixeg-12 © Q SS _Consides ye@l world Scenario data — yandomly distributed Unbalanced caches. How +o handle +his issue ? tytual 4 i => ‘Instead of mapping each node tp o single pelnt we mop fr to oultipie peints. seem S( move number of Yeplicas _ Ls more equal distvibution —__________Lrayeod load balancing) | u& Client - Sevver Communication Protocols . inet SR Fe ceaaay— 4 HTTP Protocol : ccummme, Wiss.” Request Prepare“Response 4 ATAX Polling Clients vepeatedly polls sewers for data Similoy +p ITP Protocol Ly vequest sent to Server at xequlay, Intewals (0-5 sec) 2 42, whacks + Client Keeps asking the seyvvey new data Ly Lot of response ave Sempty’? _ L, HTTP Overhead . Rey est eee ¢ “tespanse |S Resuest z 1 Ee nee £ Rexpare| T Repiest z __— — 2 Response 4+ HOP Lag Pouings “Hanging GET? Sewer does NOT send empty yesponse . Pushes vesponse {> clients only when new data is available .— )- Client makes HTTP Request 2 waits for the LESPONSE - 30 Ick request € : full response ur xeques an ——_» < —— full _Yesponse UPpyequest ; to —_—— Pauly yes ponse —_ Exnduplex communtcation chanel! over single TCP Connection, — Provides ‘ Persistent communication’ Celtent & sesver can_send data at anytime ) — bidirectional communication is alwoys open channel: Handshake Success Yesponse. ar — Ses Spenbianiedonal ——_ Communication $$$» channel > Lowey Overheads. > Real Hime dato-tansfer- Client’ establishes persistent % long -texm connection with seryvey Sexvey_ uses -this connecHon +o send data to client *x (TE cient wonts +o send data to server G Requives another tedhnclogy | protecel. data yeqwies: using vegulay HTTP == Saree open ee (28 communica: — seem wesponses whenever new data asjaljable —> best when we need yeal-time data from server +o cllent OR server is geneyating dato in a Jone & will be sending multple events to the Client.

You might also like