Home/Low-level design/File Storage System

File Storage System

Quota accounting and explicit expiration

Quota is owned by stored entries, including copies. Copying metadata does not share its quota charge; deleting one name must not free another name's bytes. Absolute expiry belongs to the stored object and copying it does not restart its TTL.

go
createdAt, ttl := 2, 5
absoluteExpiry := createdAt + ttl
fmt.Println(absoluteExpiry) // 7, even if metadata is copied at time 4

Time advances only through AdvanceTo, keeping reads and searches predictable. Expiry and deletion each release usage once. Validate metadata before duplicate or quota checks so invalid attempts cannot be hidden by capacity failures. Empty files remain real entries even with zero quota; absence cannot be represented by size zero.

Go models this service with a struct and pointer-receiver methods. Constructor functions return a pointer; validation failures return errors rather than panicking. Scalars in snapshot structs are copied by value. Maps, slices, and optional pointers still require detached copies when crossing the service boundary. Go maps do not have key iteration order; use ordered slices for ranked results. There are no threads, persistence, wall-clock reads, or external side effects in this exercise.

Put it into practice

Implement the exercise in a full-screen workspace, then run its tests.

Open practice
Next lessonMeeting Room Booking System