Store Photos in Blobstore or as Blobs in Datastore - Which is better/more efficient /cheaper?

Joe Bourne picture Joe Bourne · Feb 20, 2012 · Viewed 9.7k times · Source

I have an app where each DataStore Entity of a specific kind can have a number of photos associated with it. (Imagine a car sales website - one Car has multiple photos)

Originally since all the data is being sourced from another site, I was limited to having to store the photos as DataStore Blobs, but now that its possible to write BlobStore items programatically, I'm wondering if I should change my design and store the photos as BlobStore items?

So, the question is:
Is it 'better' to store the photos in the Blobstore, or as Blobs in the Datastore? Both are possible solutions, but which would be the better/cheaper/most efficient approach, and why?

Answer

Peter Knego picture Peter Knego · Feb 20, 2012

Images served from BlobStore have several advantages over Datastore:

  1. Images are served directly from BlobStore, so request does not go through GAE frontend instance. So you are saving on frontend instances time and hence cost.

  2. BlobStore storage cost is roughly half of Datastore storage cost ($0.13 vs $0.24). With Datastore you'd additionally pay for get() or query().

  3. BlobStore automatically uses Google cache service, so the only cost is cost of bandwidth ($0.12/GB). You can also set this on frontend instance via cache control, but the difference is that this is done automatically for BlobStore.

  4. Images in BlobStore can be served via ImageService and can be transformed on the fly, e.g. creating thumbnails. Transformed images are also automatically cached.

  5. Binary blobs in Datastore are limited to 1Mb in size.

One downside of BlobStore is that it has no access controls. Anybody with an URL to blob can download it. If you need ACL (Access Control List) take a look at Google Cloud Storage.

Update:

Cost wise the biggest saving will come from properly caching the images:

  1. Every image should have a permanent URL.
  2. Every image URL should be served with proper cache control HTTP headers:

    // 32M seconds is a bit more than one year 
    Cache-Control: max-age=32000000, must-revalidate
    

you can do this in java via:

httpResponse.setHeader("Cache-Control", "max-age=32000000, must-revalidate");

Update 2:

As Dan correctly points out in the comments, BlobStore data is served via a frontend instance, so access controls can be implemented by user code.