Theory
Build કરતા પહેલાં design કરો
Plan વગર house build ન કરો, તેમ software પણ design વગર build ન કરવું જોઈએ. Requirementsમાંથી સીધા code પર jump કરશો તો tangled અને unplanned structure બને છે, જેને build અને test કરવું મુશ્કેલ થાય છે અને teamમાં divide કરવું લગભગ અશક્ય બને છે.
System design coding પહેલાં structureનું planning છે અને તે 2 levels પર થાય છે: High-Level Design (HLD), એટલે big picture, અને Low-Level Design (LLD), એટલે દરેક ભાગની અંદરની details. બંને levels પર design કરવાથી vague idea clear blueprintમાં ફેરવાય છે, જેના આધારે team parallel અને confidently build કરી શકે છે.
Theory
High-Level Design: big picture
High-Level Design (HLD) systemનો bird's-eye view છે. તેમાં major modules અથવા components ઓળખાય છે, જેમ કે user-authentication module, event module, registration module અને reporting module. તે બતાવે છે કે modules કેવી રીતે interact કરે છે, overall architecture શું છે અને modules વચ્ચે data કેવી રીતે flow થાય છે.
HLDનો મુખ્ય પ્રશ્ન છે: main parts કયા છે અને તેઓ કેવી રીતે fit થાય છે? Internal detailsમાં ગયા વગર systemનો shape નક્કી થાય છે. Good HLDથી આખી team structure એક નજરે સમજી શકે છે અને પોતાનો ભાગ બીજા parts સાથે કેવી રીતે connect થશે તે જાણી શકે છે. HLD આખી systemનો map છે.
Theory
Low-Level Design: દરેક ભાગની અંદર
Low-Level Design (LLD) દરેક moduleની અંદર zoom કરે છે અને તેની internals detail કરે છે: classes, functions અથવા methods, data structures, algorithms અને logic.
LLDનો મુખ્ય પ્રશ્ન છે: દરેક part અંદરથી કેવી રીતે કામ કરે છે? Registration module માટે LLDમાં register, cancel અને list attendees જેવી functions, તેમનો data અને behaviour specify થાય. HLD map આપે છે, જ્યારે LLD map પરની દરેક building માટે detailed plan આપે છે.
HLD અને LLD મળીને આખી systemથી લઈને દરેક partના internal working સુધીનું design cover કરે છે. તેથી code લખતી વખતે structure invent કરવાની જગ્યાએ clear design implement કરો. પહેલાં બંને levels પર design કરો, પછી code કરો.
Quiz
નીચેનામાંથી કયું Low-Level Design (LLD) કરતાં High-Level Design (HLD)નો ભાગ છે?
- Registration moduleની અંદરની exact functions અને તેમનું logic
- Authentication, events, registration અને reporting જેવા major modules તથા તેઓ કેવી રીતે interact કરે છે તે ઓળખવું
- એક classની અંદર વપરાતી data structures
- એક method માટેનો step-by-step algorithm
Show the answer
Authentication, events, registration અને reporting જેવા major modules તથા તેઓ કેવી રીતે interact કરે છે તે ઓળખવું
HLD big-picture view છે: major modules identify કરવાં અને તેઓ કેવી રીતે interact કરે છે તે બતાવવું. Option B exactly HLD છે. Options A, C અને D LLD concerns છે: individual moduleની functions અને logic, classની internal data structures અને methodનો algorithm: all internal details છે. HLD પૂછે છે 'parts કયા છે અને કેવી રીતે fit થાય છે?'; LLD પૂછે છે 'દરેક part અંદરથી કેવી રીતે કામ કરે છે?'
Think first
માત્ર modulesનું coding શરૂ કરવાને બદલે બે levels પર design શા માટે?
HLD અને LLD અલગથી બનાવવાની જરૂર શા માટે? સીધા codeમાં dive કરવું સરળ નથી? પછી tap.
Show the answer
કારણ કે બે levels પર design કરવાથી codeમાં commit કરતાં પહેલાં STRUCTURE સાચી કરી શકાય છે. આ costly rework અટકાવે છે, teamને parallel કામ કરવા દે છે અને system સમજવા સરળ બનાવે છે. Design વગરનું coding tangled structure બનાવે છે જેને build, test અને change કરવું મુશ્કેલ હોય છે.
HLD પહેલા big questions settle કરે છે: major parts કયા, તેઓ કેવી રીતે interact કરે અને overall shape શું છે? આ પછીથી બદલવું expensive છે. Coding halfway થયા પછી modules ખોટી રીતે divide થયા છે અથવા fit થતા નથી એવું જણાય તો ઘણું code rewrite કરવું પડે. HLD teamને work sensibly divide કરવા પણ દે છે: modules અને interfaces clear હોય તો અલગ લોકો parallelમાં build કરી શકે છે.
LLD પછી દરેક moduleની classes, functions અને logic implementation પહેલાં નક્કી કરે છે. તેથી code કરતી વખતે design અને coding બંને એકસાથે invent કરવાની confusion રહેતી નથી. Hard thinking પહેલેથી થઈ જાય છે અને coding focused અને confident બને છે.
Design diagrams અને specifications documentation અને shared understanding પણ આપે છે. Design skip કરીને 'time save' કરવો false economy છે; શરૂઆતમાં બચેલો સમય પછી rework, integration problems અને debuggingમાં અનેક ગણો ગુમાય છે. Big picture પછી details: આ two-level design projectને risky improvisationમાંથી organised buildમાં ફેરવે છે.
Summary
Key takeaways
- System design coding પહેલાં structureનું planning છે અને tangled, unplanned mess અટકાવે છે.
- તે 2 levels પર થાય છે: High-Level Design (HLD) અને Low-Level Design (LLD).
- HLD big picture છે: major modules/components, તેમનું interaction અને overall architecture.
- HLDનો પ્રશ્ન: parts કયા છે અને તેઓ કેવી રીતે fit થાય છે?
- LLD દરેક moduleની અંદર zoom કરે છે: classes, functions, data structures, algorithms અને logic.
- LLDનો પ્રશ્ન: દરેક part અંદરથી કેવી રીતે કામ કરે છે?
- Memory hook: HLD big picture છે, LLD close-up છે; પહેલાં design કરો, પછી code કરો.