Sri Sri Satyatmateertha Swamiji of Uttaradimath travelling in Driverless Car At RV College.Projected Funded by Wipro Engineering,Jointly Developed By Wipro,IISc & RV College Of Engineering Bengaluru...🙂👌👏
Superb Technology. 🤘
@anandmahindra@elonmusk@nikhilkamathcio .
Top 7 Cache Eviction Strategies You Should Know:
1. 𝐋𝐞𝐚𝐬𝐭 𝐑𝐞𝐜𝐞𝐧𝐭𝐥𝐲 𝐔𝐬𝐞𝐝 (𝐋𝐑𝐔)
- Removes the least recently accessed item first.
- Works well when older data is less likely to be used again.
- Example: Browsers use LRU to discard old pages from memory when opening new tabs.
2. 𝐋𝐞𝐚𝐬𝐭 𝐅𝐫𝐞𝐪𝐮𝐞𝐧𝐭𝐥𝐲 𝐔𝐬𝐞𝐝 (𝐋𝐅𝐔)
- Evicts the least accessed items over time.
- Prioritizes keeping frequently used items in cache.
- Example: CDNs use LFU to keep trending videos in cache while removing rarely watched ones.
3. 𝐌𝐨𝐬𝐭 𝐑𝐞𝐜𝐞𝐧𝐭𝐥𝐲 𝐔𝐬𝐞𝐝 (𝐌𝐑𝐔)
- Opposite of LRU – evicts the most recently accessed item first.
- Useful when recent data becomes obsolete quickly.
- Example: In a music streaming app, the last played song is less likely to be played again, making MRU a better choice.
4. 𝐓𝐢𝐦𝐞 𝐭𝐨 𝐋𝐢𝐯𝐞 (𝐓𝐓𝐋)
- Items are evicted after a set time limit (expiry time).
- Prevents stale data, useful in distributed systems.
- Example: DNS records have TTL values, so if an IP address changes, clients don’t hold onto outdated mappings.
5. 𝐅𝐢𝐫𝐬𝐭 𝐈𝐧, 𝐅𝐢𝐫𝐬𝐭 𝐎𝐮𝐭 (𝐅𝐈𝐅𝐎)
- Evicts the oldest stored item first, regardless of usage.
- Simple to implement but may remove still-relevant data.
- Example: Simple queue-based caching systems.
6. 𝐑𝐚𝐧𝐝𝐨𝐦 𝐑𝐞𝐩𝐥𝐚𝐜𝐞𝐦𝐞𝐧𝐭 (𝐑𝐑)
- Randomly evicts an item when the cache is full.
- Low overhead, but less predictable performance.
- Example: Some network routers use RR for managing limited memory, avoiding complex eviction policies.
7. 𝐓𝐰𝐨-𝐓𝐢𝐞𝐫𝐞𝐝 𝐂𝐚𝐜𝐡𝐢𝐧𝐠
- Uses a fast in-memory cache (e.g., Redis) & a slower persistent cache (e.g., disk-based).
- Optimizes speed & storage by balancing hot and cold data.
- Example: A CDN stores frequently accessed content in RAM (L1 cache) while keeping less-accessed content on disk (L2 cache) to balance performance and cost.
💡 No single strategy is perfect—the right choice depends on:
- Data access patterns (frequent reads? high writes?)
- System constraints (memory, CPU, disk space)
- Performance trade-offs (latency vs accuracy)
♻️ Repost to help others in your network.
Choosing the right architecture will make or break your systems.
EDA vs. REST a Simple Cheatsheet.
Event-Driven Architecture (EDA)
EDA uses asynchronous communication, where components interact by emitting and consuming events.
This design is particularly effective for systems that demand high scalability, real-time responsiveness, and loose coupling among services.
Representational State Transfer (REST)
It is a popular choice for building web services that require synchronous, request-response communication over HTTP.
It's ideal for applications where strong consistency, simplicity, and standard CRUD operations are necessary.
However, REST can face challenges in scenarios requiring near real-time communication or scaling dynamically.
Even more important, these architectures are not mutually exclusive.
Many modern systems benefit from a hybrid approach.
Choose wisely!
How can Cache Systems go wrong?
The diagram below shows 4 typical cases where caches can go wrong and their solutions.
1. Thunder herd problem
This happens when a large number of keys in the cache expire at the same time. Then the query requests directly hit the database, which overloads the database.
There are two ways to mitigate this issue: one is to avoid setting the same expiry time for the keys, adding a random number in the configuration; the other is to allow only the core business data to hit the database and prevent non-core data to access the database until the cache is back up.
2. Cache penetration
This happens when the key doesn’t exist in the cache or the database. The application cannot retrieve relevant data from the database to update the cache. This problem creates a lot of pressure on both the cache and the database.
To solve this, there are two suggestions. One is to cache a null value for non-existent keys, avoiding hitting the database. The other is to use a bloom filter to check the key existence first, and if the key doesn’t exist, we can avoid hitting the database.
3. Cache breakdown
This is similar to the thunder herd problem. It happens when a hot key expires. A large number of requests hit the database.
Since the hot keys take up 80% of the queries, we do not set an expiration time for them.
4. Cache crash
This happens when the cache is down and all the requests go to the database.
There are two ways to solve this problem. One is to set up a circuit breaker, and when the cache is down, the application services cannot visit the cache or the database. The other is to set up a cluster for the cache to improve cache availability.
Over to you: Have you met any of these issues in production?
–
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/FIzCeaWsZV
@DKShivakumar Dear Sir, in the notification we find 16/1, 16/2 being acquired. This impacts 300 families and 1000 residents along with jobs of countless staff. (1/n)
8 Key Data Structures That Power Modern Databases
🔹Skiplist: a common in-memory index type. Used in Redis
🔹Hash index: a very common implementation of the “Map” data structure (or “Collection”)
🔹SSTable: immutable on-disk “Map” implementation
🔹LSM tree: Skiplist + SSTable. High write throughput
🔹B-tree: disk-based solution. Consistent read/write performance
🔹Inverted index: used for document indexing. Used in Lucene
🔹Suffix tree: for string pattern search
🔹R-tree: multi-dimension search, such as finding the nearest neighbor
Over to you: did we miss anything?
--
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/uc5M7CdXXC
Logging, tracing and metrics are 3 pillars of system observability.
The diagram below shows their definitions and typical architectures.
🔹 Logging
Logging records discrete events in the system. For example, we can record an incoming request or a visit to databases as events. It has the highest volume. ELK (Elastic-Logstash-Kibana) stack is often used to build a log analysis platform. We often define a standardized logging format for different teams to implement, so that we can leverage keywords when searching among massive amounts of logs.
🔹 Tracing
Tracing is usually request-scoped. For example, a user request goes through the API gateway, load balancer, service A, service B, and database, which can be visualized in the tracing systems. This is useful when we are trying to identify the bottlenecks in the system. We use OpenTelemetry to showcase the typical architecture, which unifies the 3 pillars in a single framework.
🔹 Metrics
Metrics are usually aggregatable information from the system. For example, service QPS, API responsiveness, service latency, etc. The raw data is recorded in time-series databases like InfluxDB. Prometheus pulls the data and transforms the data based on pre-defined alerting rules. Then the data is sent to Grafana for display or to the alert manager which then sends out email, SMS, or Slack notifications or alerts.
Over to you: Which tools have you used for system monitoring?
--
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/FIzCeaWsZV