Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving images when using Couchbase as app server?

Tags:

couchbase

I'm working on a little express app which currently allows users to login (via passport) and see information regarding their friends, i.e. purchase history, likes etc. Ideally I want each user to have an accompanying profile photo and for items in their purchase history to have accompanying product photos. A simplified user model is shown below

{
  "name": "Homer Simpson",
  "purchases": "Duff"
}

If I want a profile photo to go with this, is there a straightforward way to do it in couchbase, or should I store it in something like S3 and then have

{
  "name": "Homer Simpson",
  "profile_pic" : "http://s3.something.com/profilepics/homer.jpg",
  "purchases": "Duff"
}
like image 531
Philip O'Brien Avatar asked Jun 19 '14 09:06

Philip O'Brien


1 Answers

I can give you two arguments of why I would not store them in the database (Couchbase or otherwise).

1) Use each tool for what it is best at. Couchbase can serve up that example document you give right from its managed cache in RAM. You will get sub millisecond response time. S3 is excellent at serving up static content like images. Can Couchbase serve up that image very fast from RAM as well? Sure, but you are going to use more resources to do it and that leads me to my #2 argument.

2) By storing the image in a DB, Couchbase or otherwise, you would be using your most expensive and performant resources for something that is static and changes infrequently. Just think of the cost of storage on an EC2 instance as compared to S3. If you were to store that in a database, you have to store it, replicate it, back it up, etc. along side your critical data. S3 is great at having high durability at an exceedingly reasonable price. Images in a database sounds like a great idea, but over time they become chains around your neck. Unless you start now with a user account expiration policy, you could be 2 years from now and storing, backing up and replicating images in from a user that quit using your service 1.5 years ago and paying for every KB multiple times. Again, this is not exclusive to Couchbase by any means.

Go with the document that has the pointer to the image in S3 is my opinion. You will get the best of both world. Performance and cost effectiveness for not much extra work.

like image 194
Kirk Avatar answered Sep 22 '22 06:09

Kirk