Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis for caching image files?

I am using Amazon S3 for storing and retrieving images for an image storing website. The trouble is that multiple users have to retrieve same image multiple times.

Is it suggested to use Redis or memcached for caching image files by storing them directly onto it.

Amazon S3 pricing for data transfer is much higher than compared to serving images via Redis cache. But storing image files directly on Redis seems to be a bad proposition because I read somewhere that Redis is not good for operating on large data files. Also I don't understand that if Redis stores data on memory how will it store so many images(unless I make many many instances).

Is it advisable to store image files directly onto Redis or is there an alternate for caching these images?

Do pinterest and imgur use Redis and memcache for storing images directly? If not why do they have so many instances?Pinterest

like image 294
Mayank Avatar asked Jun 07 '16 14:06

Mayank


People also ask

Can we store images in Redis cache?

You can store the image in binary instead of base64 and it will be more efficient: In RAM memory usage on your redis server. In Network usage. In compute (CPU) usage assuming you are passing the images in binary to the final client.

Is Redis good for caching?

Caching. Redis is a great choice for implementing a highly available in-memory cache to decrease data access latency, increase throughput, and ease the load off your relational or NoSQL database and application.

Can Redis cache files?

Redis can be used for storing any data, the only limitation is that its protocol supports strings of up to 512MB - if your files are smaller than that, there shouldn't be any problem.

How is Redis used for caching?

How Redis cache works is by assigning the original database query as the key and then resulting data as the value. Now, the Redis system can access the resulting database call by using the key which it has stored in its built-in temporary memory.


1 Answers

You get credit for creativity, but you have not found a loophole, here.

First, it's entirely inappropriate to try to serve images from elasticache. It's a cache. It's volatile by definition.

Second, it's not a web server.

Third, it's not intended to be exposed to the Internet.

But even if these aren't persuasive, your question seems premised on a misunderstanding of the pricing structure on several levels.

There is no Amazon ElastiCache Data Transfer charge for traffic in or out of the Amazon ElastiCache Node itself.

https://aws.amazon.com/elasticache/pricing/

Technically, this is accurate, but it is not helpful.

This is only relevant to the transfer from elasticache to your EC2 instance. You still have to return the data to the browser, across the Internet, and this costs the same, whether you return it from/through EC2, or from S3.

Data Transfer OUT From Amazon EC2 To Internet

Up to 10 TB / month $0.09 per GB

https://aws.amazon.com/ec2/pricing/

...or...

Data Transfer OUT From Amazon S3 To Internet

Up to 10 TB / month $0.090 per GB

https://aws.amazon.com/ec2/pricing/

Meanwhile, CloudFront is $0.085/GB for traffic sent to browsers that are accessing edge locations in the lowest price class, US and Europe. And you control which edge locations are available when you select a price class other than the global one:

If you choose a price class that does not include all edge locations ... you're charged the rate for the least expensive region in your selected price class.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PriceClass.html

That's $0.085 if configured correctly.

There is no charge for transfer from S3 to CloudFront or from EC2 to CloudFront. Only the charge from CloudFront to the Internet.

like image 78
Michael - sqlbot Avatar answered Nov 03 '22 17:11

Michael - sqlbot