Cache Avalanche Cache Avalanche

Problem description

Cache avalanche refers to the breakdown of the Redis cluster. Clients cannot obtain data from Redis, and a large number of requests are sent to mysql. As a result, the number of requests processed by mysql surges, the DB is suspended, and services are unavailable.

The solution

1 To ensure high availability of Redis cluster, master-slave architecture, sentry mode 2 downgrading & limiting flow, avoid mysql to bear too much pressure 3 Redis persistence, quick restart after fault recovery, support services

Cache Penetration

Problem description

Cache penetration refers to the fact that neither mysql nor Redis has the data that the user wants to query. For example, hackers simulate request attacks and cause db to fill up.

The solution

1 Solution at the service layer: Verify the request parameter format and query the redis key format. If the key format does not meet the requirement, an error is returned. 2 Solution at the storage layer: If the query data is NULL, set key NULL in Redis to avoid query failure. 3 Use bloom filter to store the key. When the request comes in, bloom filter is used to search for the key

Cache breakdown Hotspot Invalid

Problem description

A certain key is hotspot data. When the expire time expires, a large number of requests cannot be queried. As a result, a DB bottleneck occurs.

The solution

1 avoid a large number of keys expiring at the same time. You can set the expire time of keys to a random value in a certain interval. 2 Start a CT task to reset the expire time of keys in REDis (this scheme will increase maintenance costs).