As the lead for an R2 bucket of user photos, thumbnails and videos, how would you set its storage-class and lifecycle policy?
answer
- egress is free, retrieval is not
- a 30-day minimum duration
- rules match by key prefix
- no lifecycle path back to Standard
basics
~20 sKeep frequently read data such as thumbnails in Standard and move only long-tail originals to Infrequent Access, which stores for a third less but adds retrieval fees, a 30-day minimum and pricier operations. Abort stale multipart uploads and expire staging objects.
solid answer
~50 sAs of 2026-10-10, Standard costs $0.015 per GB-month and Infrequent Access $0.01, but Infrequent Access adds $0.01 per GB retrieved, a 30-day minimum storage charge, Class A at $9.00 instead of $4.50 per million and Class B at $0.90 instead of $0.36, and it gets no free tier. The saving is $0.005 per GB-month, so reading an object in full about once every two months erases it. Thumbnails, read constantly, stay in Standard; video originals cross over once views fade. Lifecycle rules match by key prefix, so the key layout (`thumbs/`, `videos/originals/`, `staging/`) decides what the policy can express. Each transition is a Class A operation, a lifecycle rule cannot move an object back to Standard (that takes a rewrite, such as a `CopyObject`), and expiry wins over transition when both fall within 24 hours. I would also shorten the multipart abort window from the default seven days and own the rules as reviewed configuration.
code
bash · 4 linesnpx wrangler r2 bucket lifecycle add user-uploads abort-stale-video-uploads videos/ --abort-multipart-days 1
npx wrangler r2 bucket lifecycle add user-uploads expire-staging staging/ --expire-days 2
npx wrangler r2 bucket lifecycle add user-uploads originals-to-ia videos/originals/ --ia-transition-days 90
npx wrangler r2 bucket lifecycle list user-uploadsgo deeper
Recall the two storage classes, that Infrequent Access is cheaper to store but charges for retrieval, and that lifecycle rules move or delete objects by age.
Explain the 30-day minimum, the higher operation prices, why expiry beats transition within 24 hours, and the default seven-day multipart abort.
Work out a break-even from real read rates per prefix, and know that leaving Infrequent Access takes a rewrite that costs a retrieval.
Own the policy as a team rule: a key layout that lets rules target data classes, who may change defaults, and when product changes reopen the decision.
## What the two storage classes cost R2 has two **storage classes**, chosen per object at upload (`storageClass` in `put()`), by the bucket's default, or later by a **lifecycle rule**. Both have the same durability and work with the binding, the S3 API and public access. They differ in their pricing terms, here as listed on 2026-10-10: | | Standard | Infrequent Access | |---|---|---| | Storage | $0.015 / GB-month | $0.01 / GB-month | | Class A operations (writes, lists) | $4.50 / million | $9.00 / million | | Class B operations (reads) | $0.36 / million | $0.90 / million | | Data retrieval | none | $0.01 / GB | | Minimum storage duration | none | 30 days | | Free tier | 10 GB-month, 1M Class A, 10M Class B | not applicable | Neither class charges **egress**. That changes the usual reasoning: on R2 the retrieval fee and the operation prices are the only costs that grow with reads. ## Where Infrequent Access pays off Infrequent Access saves $0.005 per GB-month and charges $0.01 per GB read. Reading an object in full once every two months cancels the saving, before the higher operation prices are counted. - **Thumbnails**: small, read on every page view, replaced when a user changes their photo. Each read pays the dearer Class B price, each replacement inside 30 days still bills the full 30 days, and the saving per object is tiny. Keep them in Standard. - **Recent videos**: watched heavily in the first weeks. Keep them in Standard. - **Old video originals**: large and rarely played after a few months. This is the long-tail data the class is built for. - **Staging objects and abandoned uploads**: neither class is right for them; they should be deleted. A worked example: 10 TB of video originals older than 90 days, of which 2% is played in a month. Moving them saves about $50 a month in storage, while the 200 GB read back costs about $2 in retrieval plus a small rise in Class B charges. The same move for 50 GB of thumbnails read thousands of times a day would save $0.25 and cost far more in retrieval and reads. Measure before choosing the age: read counts by object age, from your own view statistics or the bucket's operation metrics, set the transition day better than a guess. ## Key layout decides what a rule can target A lifecycle rule applies to the whole bucket or to one **key prefix**, and a bucket can hold up to 1,000 rules. A layout such as `thumbs/<user>/`, `videos/originals/<user>/` and `staging/` lets each data class get its own rule. A layout keyed by user first (`<user>/thumb.jpg`, `<user>/video.mp4`) gives you no prefix that means "video originals", so changing the layout later means rewriting keys. Settle the layout before the bucket fills. ## A starting policy for the uploads bucket 1. **Abort unfinished multipart uploads after one day** on `videos/`, instead of the default seven. 2. **Expire `staging/` after two days**, where uploads wait for validation. 3. **Transition `videos/originals/` to Infrequent Access after 90 days**, revisited once real read data exists. 4. **Leave `thumbs/` in Standard** with no transition, and keep the bucket's default class Standard. 5. Delete a user's objects when the account is deleted, through your own code, since lifecycle rules know nothing about accounts. ## Traps in lifecycle behaviour - Rules act within about 24 hours, not at an exact moment; an object can outlive its expiry date briefly. - Each transition to Infrequent Access is a **Class A operation**, so moving millions of small objects has a cost of its own. - When an expiry and a transition fall within the same 24 hours, the **expiry wins**. - **There is no lifecycle path back.** An object that becomes popular again returns to Standard only by being rewritten, typically an S3 API `CopyObject` onto itself with storage class `STANDARD`, which costs a Class A operation and a retrieval. - Deleting or replacing an Infrequent Access object before 30 days still bills the full 30 days. ## Owning the policy - Keep lifecycle rules in reviewed scripts (`wrangler r2 bucket lifecycle set <bucket> --file <rules.json>`) rather than ad hoc dashboard edits, so the bucket's behaviour is visible in code review. - Review the rules when the product changes how media is used, for example a "memories" feature that resurfaces old videos would turn the cold tier into a retrieval bill. - Decide who may change a bucket's default storage class, since one switch changes the cost of every later upload.
- An R2 video moved to Infrequent Access becomes popular again. How do you bring it back to Standard?Lifecycle rules only move objects toward Infrequent Access, never back. Rewrite the object: copy it onto itself with the S3 API's `CopyObject` and storage class `STANDARD` (the `x-amz-storage-class` header), or read it in a Worker and `put()` it again with `storageClass: "Standard"`. The copy is a Class A operation, reading the source incurs the retrieval fee, and if the object spent under 30 days in Infrequent Access the minimum duration is still billed.
- Why could setting an R2 bucket's default storage class to Infrequent Access backfire for thumbnails?Every new upload would land there, including thumbnails read on every page view. Each read then pays $0.90 instead of $0.36 per million plus a retrieval fee, each replaced thumbnail is billed for 30 days, and the free tier covers none of it. The default suits a bucket that holds only archival data.
Infrequent Access is like a storage unit with cheap rent but a fee each time you open the door: ideal for boxes you rarely touch, ruinous for the toolbox you open every day.
- Infrequent Access is always cheaper because R2 charges no egress
- A lifecycle rule can move objects back to Standard when they get popular
- Deleting an Infrequent Access object after five days stops its storage charge
- R2's free tier covers the first 10 GB of Infrequent Access storage
- Transitioning millions of small objects to Infrequent Access costs nothing
Prices and the 30-day minimum are R2's published pricing as of 2026-10-10; Cloudflare changes prices independently of any API.