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

前端 未结 1 1589
感动是毒
感动是毒 2020-12-02 08:15

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)

相关标签:
1条回答
  • 2020-12-02 08:34

    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.

    0 讨论(0)
提交回复
热议问题