Write Shape to Base Mechanism Cheat Sheet
Write Shape to Base Mechanism Cheat Sheet #
Use this as a default mapping from a normalized path shape to an implementation mechanism family. This is not a proof of the final design. It is a fast first-pass heuristic.
1. Create Target #
Examples:
- create post
- create profile
- create order
- create comment
Default base mechanism:
- insert/create in primary store
Common implementation forms:
- insert row
- append to primary table
- create object in key-value store
When to refine:
- if duplicate retries matter, add idempotency key
- if child object is append-heavy, consider append log/table
2. Overwrite Current Value #
Examples:
- rename file
- edit profile headline
- update document title
- update feature flag rule
Default base mechanism:
- versioned overwrite
Common implementation forms:
- update by version
- optimistic concurrency control
- last-writer-wins only when business semantics allow it
When to refine:
- if stale writes are dangerous, require CAS/version match
3. State Transition #
Examples:
- follow/unfollow
- revoke sharing
- cancel booking
- approve refund
- accept suggestion
Default base mechanism:
- guarded conditional update
Common implementation forms:
- conditional update on current state/version
- lifecycle transition in primary row/object
- optimistic concurrency with state predicate
When to refine:
- if exclusivity matters, combine with claim/lease semantics
- if multiple objects move together, add workflow orchestration
4. Append Event #
Examples:
- audit log event
- activity event
- bid
- metric sample
- span record
Default base mechanism:
- append log or append table
Common implementation forms:
- immutable insert
- event log
- time-series append
When to refine:
- if ordering matters, define ordering scope
- if dedup matters, add event/request id
5. Read Source #
Examples:
- view current order status
- read current document
- read current seat availability
- introspect session
Default base mechanism:
- source read from authoritative state
Common implementation forms:
- primary DB read
- shard owner read
- strongly consistent read path
When to refine:
- if bounded stale is allowed, add replica or cache read rules
6. Read Projection #
Examples:
- home feed
- search results
- top K tags
- dashboard
- leaderboard
Default base mechanism:
- materialized view or search/index read model
Common implementation forms:
- search index
- feed table
- ranking cache
- precomputed aggregation
When to refine:
- if user needs read-your-write, add hybrid source + projection path
7. Projection Write / Update #
Examples:
- increment follower count
- update top tags
- update feed fanout table
- update search index
Default base mechanism:
- counter/projection update
Common implementation forms:
- counter increment/decrement
- async materialized view maintenance
- search indexing worker
- batch recompute
When to refine:
- if exactness matters, prefer idempotent deltas or recompute from source truth
8. Exclusive Claim #
Examples:
- acquire lock
- worker claims job
- claim reminder notification run
- assign one executor to a runnable unit
Default base mechanism:
- claim/lease
Common implementation forms:
- lease record with expiry
- claim token
- fencing token / epoch
When to refine:
- if crash recovery matters, make expiry and fencing explicit
9. Time-Bounded Exclusive Allocation #
Examples:
- hold seat
- hold hotel room
- hold appointment slot
Default base mechanism:
- guarded conditional update with claim/lease semantics
Common implementation forms:
- resource state transition + hold record
- hold expiry index
- fencing/epoch if stale holders can act later
When to refine:
- if commit follows hold, add booking/order workflow object
10. Frontier Advance #
Examples:
- advance campaign recipient frontier
- advance crawler cursor
- advance scheduler next due boundary
Default base mechanism:
- guarded frontier advance
Common implementation forms:
- versioned cursor update
- monotonic pointer/frontier write
- claim-next-batch under current frontier
When to refine:
- if materializing runs, pair with
create target
11. Future Constraint to Claimable Run #
Examples:
- due reminder creates notification job
- delayed task becomes runnable
- scheduled run fires
Default base mechanism:
- due-time scan plus create target, often followed by claim/lease
Common implementation forms:
- index by
run_at - scheduler scan
- materialize runnable item
- worker claim token
When to refine:
- if exactly-once due materialization matters, add guarded version update
12. Control Plane Snapshot Publication #
Examples:
- push feature flag config
- publish policy snapshot
- publish validator snapshot
- publish config version to consumers
Default base mechanism:
- versioned snapshot publication
Common implementation forms:
- push or pull-after-notify
- snapshot overwrite
- monotonic version application
When to refine:
- if rollout matters, track published versus applied version separately
Quick Mapping Table #
| Write shape | Default base mechanism |
|---|---|
| create target | insert/create |
| overwrite current value | versioned overwrite |
| state transition | guarded conditional update |
| append event | append log/table |
| read source | authoritative source read |
| read projection | materialized view / search index |
| projection write | counter/projection update |
| exclusive claim | claim/lease |
| time-bounded exclusive allocation | guarded update + hold/lease |
| frontier advance | guarded frontier update |
| future due -> runnable | due scan + create target |
| control-plane publication | versioned snapshot publication |
Interview One-Liner #
After I normalize a path, I pick its write shape first. That usually suggests the first mechanism family: create maps to insert, overwrite maps to versioned overwrite, lifecycle changes map to guarded conditional updates, append facts map to append logs, claim paths map to leases, and feeds/search/top-K map to materialized views.