Laravel app using Redis on a different server (with a different provider)
I'm hosting a Laravel application on Amazon (Elastic Beanstalk).
I've been looking into Amazon ElastiCache for caching and queuing, but I'm also investigating a set-up where I host Redis somewhere else. The reason is fairly simple: I find the ElastiCache service with Amazon overpriced. I kind of want a server with more power on the RAM side, not caring so much about more CPU cores. Other hosting companies are offering better deals in this area.
Now to my question:
What are the performance effects (if any) when I use Redis that is hosted with a different provider? In this case:
Laravel app -> Amazon | Redis server -> different provider within the same city or close to the location the Amazon server is at.
I would say that there is not so much of a difference, as services like Redis Labs also offer cloud-based Redis solutions where my app would contact a server over the Internet for Redis.
Is there anything else that I might have overseen?
I am not sure if you have a big advantage by offloading the cache to an external server. For 'Queues' this is totally fine, no question, but cache? Even Databases or the filesystem are faster then the latency between 2 servers. Or is there any magic with Redis that accelerates such things?
@Cronix yes, I figured that it would be slower because of this, but I have no idea HOW MUCH slower. If it's just a few percent it would be more than fine for me, but if it's like 2x or 3x slower it would not really pay off anymore. The same goes for the situation when file-based caching would be faster.
When I host it on another EC2 (or use ElastiCache, which is in the end nothing more than an EC-2 instance as well) data will also need to travel (though not so much hops of course)
The only advantage that I see using EC2 or ElastiCache is that I can have my servers communicate over a private network (no need to go on the internet) which would probably be significantly faster.
@Helmchen this also crossed my mind at first. But then again, there are Redis cloud-solutions out there (like Redis Labs). In this case I would also have to communicate with an external server. If this would be slower than having the cache on the local filesystem, why would I use such a service?
Database-cache I would like to avoid anyway to relieve the database from unnecessary load.
But it rises another interesting question:
Is remote Redis faster than a file-based cache (local of course) and if so, why?
Yes, routing from EC2 to EC2 in the same datacenter will be significantly faster than routing to an external host. It doesn't need to do DNS lookups on a local network or go out to the public internet like it does if it's external, and who knows how many hops the external provider uses. I've seen some pretty crazy routings using traceroute. Requests going through several different US States, when both servers are located in the same state.
You're also at the mercy of whatever pipes and infrastructure the "external" host is using, so it's another potential point of failure. I like to keep everything that I can in the same datacenter/region as there is less of a possibility of something going wrong. If something goes wrong with AWS, you're down. But if AWS is working and something happens to the other hosting company, you're down. 2 potential points of failure in that scenario.
@Cronix Yes, no doubt that this would be faster and the preferred situation is of course "all within the same network". Because of external services like Redis Labs I was starting to think that the disadvantages might not be sooo huge after all.
I'm surprised that Amazon does not offer EC2 instances with just one CPU and (much) more RAM.
The instances with more RAM also have all other resources increased, making them relatively "expensive" because Redis is single-threaded and this instance will do nothing else than Redis.
I will first try to found out how many RAM I will really need for Redis anyway, because I have no clue. It's the first time I will be using Redis. I have quite some "full pages" that will be put in Redis cache, together with a significant amount of query results, as well as all Laravel queues (jobs and e-mails) and preferably also the sessions.
Can I just use the file driver for these things, see how much data on the disk is used at max, add some on top of this to be sure and then take this as the min. required RAM for Redis? Or will Redis store it differently, meaning more (or less) storage used?