What Is Low-Level Design?
Definition
Low-level design
- In plain English
- Low-level design is deciding how the code inside one component is organised into types, functions and their relationships.
- Think of it like
- If high-level design is a house's floor plan, low-level design is the wiring and plumbing inside each room.
Machine-coding round
- In plain English
- A machine-coding round is an interview where you build a small, working, well-structured program in about 90 minutes.
- Think of it like
- It is like a cooking contest where the dish must taste good and the kitchen must stay tidy.
Why it exists
You add late fees to a tool-loan service. HandleLoan already checks members, calculates prices, saves records and sends email. One pricing edit now risks breaking four separate jobs.
package main
import "fmt"
func HandleLoan(memberID, itemID string, days int, loans map[string]int) error {
if memberID == "" || itemID == "" || days < 1 || days > 30 || loans == nil {
return fmt.Errorf("invalid member, item, duration or storage")
}
price := days * 2
loans[memberID+":"+itemID] = price
fmt.Printf("Email to %s: borrowed %s for %d credits\n", memberID, itemID, price)
return nil
}
func main() {
loans := make(map[string]int)
fmt.Println(HandleLoan("M7", "drill", 3, loans))
}
- A pricing change forces you to reread storage and email code.
- Testing member checks means running unrelated work too.
- An email failure hides whether the loan was saved.
- Separate focused operations so you can read, test and extend each rule.
How it works
- Read requirements
Write down what the program must do and the rules it must preserve.
- Underline nouns
Start with types for Member, Item and Loan.
- Circle verbs
Start with methods for Borrow, Return and Reserve.
- Decide relationships
Ask which values contain, refer to or briefly use others.
- Define interfaces where things vary
List the operations a replaceable part must provide.
- Code
Build the smallest design that satisfies the requirements.
- Test
Check normal requests and rejected requests.
- Extend
Add one new requirement and see which code must change.
The order service, shown as an HLD box, connects to three internal parts: Order, Station and Router.
package main
import "fmt"
type Loan struct{ MemberID, ItemID string }
func main() {
loan := Loan{MemberID: "M7", ItemID: "drill"}
fmt.Println(loan.MemberID, loan.ItemID)
}
Examples
Borrowing a shared drill
A member borrows an available item, returns it, or reserves it for later. Each loan records who borrowed which item.
| Requirement word | Design candidate |
|---|---|
| Member, Item, Loan | Types holding related data |
| Borrow, Return, Reserve | Methods expressing actions |
type Member struct{ ID string }
type Item struct {
ID string
Available bool
}
type Loan struct{ MemberID, ItemID string }
The insight
Nouns and verbs in requirements are your first draft of a design.
A growing pass checker
A 60-line CheckPass branches for day, season and points passes. A family pass adds another branch and another chance to break old rules.
Keep each pass rule separate once the differences keep growing. The gate should ask whether this pass allows this ride.
CheckPass branches into day, season and points rules. Below, Gate calls a Pass rule shared by DayPass, SeasonPass and PointsCard.
The insight
Good LLD isolates the part that keeps changing.
Next season’s bidding rules
The auction house plans to switch from open bidding to sealed bids next season.
Define bid acceptance and keep its rules separate from callers. Focus on this planned change.
type Bid struct{ Amount int }
type BidRule interface{ Accept(b Bid) error }
The insight
Design for the change you can already foresee, and only that change.
Trade-offs
Pros
- Readable responsibilities.
- Focused tests.
- Easier changes and a stronger interview design.
Cons
- A slower first version.
- Too many layers hide the actual task.
Use when
- Long-lived code.
- Team projects and machine-coding interviews.
Avoid when
- Throwaway scripts.
- One-off experiments with no expected extension.
Quick check
Takeaways
- LLD organises code inside one component.
- Nouns → types, verbs → methods.
- Isolate what changes.