PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] How does a distributed cache and/or global cache work?

 November 12, 2022     amazon-web-services, caching, distributed-computing, memcached     No comments   

Issue

so high level conceptual question:

How do distributed caches and global caches work?

From my understanding, requests go through a load balancer, to a web server, then to a cache. In the event of a miss, it looks in the db.

**Load Balancer > Web Server #xxxxx01 > Cache > Load Balancer > DB #xx02 **

Is this cache constant throughout all servers? For example, if I put something in my shopping cart on amazon on web server #322, is there a global cache which is replicated to cache all of the shopping carts for all of the users on all of the servers? So if I am ever routed to webserver #151, I can still get my cached shopping cart? Or does each web server have a dedicated cache and each time I log back into amazon, my request is routed to the cache where my shopping cart is?

Thanks for the clarification.


Solution

There are both type of solutions available and I have worked on both type. One of them was terracotta. It runs on independent server(master) but also it has its own client running on all different client nodes. So, whenever client asks for data it asks from local terracotta client. Now, if there is an update in shopping cart suppose then that node client updates its local terracotta client which in turn update master which in turn updates all other client nodes. So, its responsibility of terracotta to make sure data is in sync on ALL nodes and master. Ofcourse if any client dies; and comes back-up then it picks initial data from master. If data asked is NOT there on local node; it asks master for it and then keeps that data locally also.

Other solutions are like Redis/Memcache which keeps data on master node and client always goes to this master node to ask for data. Drawback is that serialization/de-serialization happen with each request.



Answered By - Deepak Singhal
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing