Storage bindings

Choose the right storage product

Match relational queries, read-heavy keys, objects, and strongly coordinated state to D1, KV, R2, or Durable Objects.

8 minute lesson

~~~

Cloudflare storage products overlap at the level of “save data,” but differ in consistency, query model, size, and coordination.

Use D1 for relational records, KV for high-read values tolerant of stale propagation, R2 for object bodies, and Durable Objects for strongly coordinated per-entity state. Recheck current product docs, limits, and pricing before committing a production design.

Start with the invariant, then choose the product. “A user can never claim the same name twice” needs coordinated or transactional enforcement. “A public list may be one minute old” can use an eventually consistent cache. “Download this exact export” fits an object key. Querying by several fields points toward relational storage.

Queues are delivery, not the source of truth, and secrets belong in bindings rather than any of these stores. For every datum, name the authoritative copy, acceptable staleness, expected access pattern, size, retention, and recovery method. If two products hold copies, define which one wins and how the derived copy is rebuilt.

Classify link records, cached public lists, export files, live collaboration rooms, secrets, and queue messages.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →