Live data from Hacker News

Ways to shoot yourself in the foot with Redis

philbooth.me

21–30 of 85 posts

Re: Ways to shoot yourself in the foot with Redis

#21
post #6

Another one: don't use distributed locks using Redis (Redlock) as if they were just another mutex. Someone on the team decided to use Redlock to guard a section of code which accessed a third-party API. The code was racy when accessed from several concurrently running app instances, so access to it had to be serialized. A property of distributed locking is that it has timeouts (based on Redis' TTL if I remember corre…

All distributed locking systems have a liveness problem: what should you do when a participant fails? You can block forever, which is always correct but not super helpful. You can assume after some time that the process is broken, which preserves liveness. But what if it comes back? What if it was healthy all along and you just couldn't talk to it?

The classic solution is leases: assume bounded clock drift, and make lock holders promise to stop work some time after taking the lock. This is only correct if all clients play by the rules, and your clock drift hypothesis is right.

The other solution is to validate that the lock holder hasn't changed on every call. For example, with a lock generation epoch number. This needs to be enforced by the callee, or by a middle layer, which might seem like you've just pushed the fault tolerance problem to somebody else. In practice, pushing it to somebody else, like a DB is super useful!

Finally, you can change call semantics to offer idempotency (or other race-safe semantics). Nice if you can get it.

Re: Ways to shoot yourself in the foot with Redis

#23
post #6

Another one: don't use distributed locks using Redis (Redlock) as if they were just another mutex. Someone on the team decided to use Redlock to guard a section of code which accessed a third-party API. The code was racy when accessed from several concurrently running app instances, so access to it had to be serialized. A property of distributed locking is that it has timeouts (based on Redis' TTL if I remember corre…

I found this blog post about Redlock quite interesting: https://martin.kleppmann.com/2016/02/08/how-to-do-distribute...

Re: Ways to shoot yourself in the foot with Redis

#24

Has anyone seen max (p100) client latencies of 300 to 400ms but totally normal p99? We see this across almost all our redis clusters on elasticache and have no idea why. CPU usage is tiny. Slowlog shows nothing.

I would guess your problem is probably scheduler based. The default(ish) Linux scheduler operates in 100ms increments, the first use of a client takes 3-4 round-trips. TCP opens, block, request is sent, the client blocks on write, the client attempts to read and blocks on read. If CPU usage is high momentarily, each of these yields to another process and your client isn't scheduled for another 100ms

Re: Ways to shoot yourself in the foot with Redis

#25
post #3

Change the default `stop-writes-on-bgsave-error` to "no" or you're asking for trouble... a ticking time bomb.

Isn’t it another ticking time bomb to accept writes that will be lost if the server is shut down?

Expecting that any key in redis will be there next time you read it is a ticking timebomb. Redis is not a database. It's a cache.

Unless you're using AOF mode with fsync always, you can lose writes. If you're doing that, you should be using a real database instead.

Re: Ways to shoot yourself in the foot with Redis

#26

Has anyone seen max (p100) client latencies of 300 to 400ms but totally normal p99? We see this across almost all our redis clusters on elasticache and have no idea why. CPU usage is tiny. Slowlog shows nothing.

Is it doing backups?

My understanding is elasticache does not let you turn them off.

Re: Ways to shoot yourself in the foot with Redis

#28
post #27

I had a jr dev connect and typed 'flushall' because he thought it would refresh the dataset to disk. thankfully it was on a staging env, I think he's at google now.

One time during my internship years ago I took down a production server because of a command I ran on it that I didn’t fully understand.

Since then I treat any prod server terminal like I’m entering launch codes for a middle system.

Anything outside of ls or cd I’m very careful, read the command a couple times before executing, etc.

Re: Ways to shoot yourself in the foot with Redis

#29
post #27

I had a jr dev connect and typed 'flushall' because he thought it would refresh the dataset to disk. thankfully it was on a staging env, I think he's at google now.

You can use rename-command to help avoid these kinds of mistakes:

  # To disable:
  rename-command FLUSHALL ""

  # To rename:
  rename-command FLUSHALL DANGER_WILL_ROBINSON_FLUSH_ALL

Re: Ways to shoot yourself in the foot with Redis

#30
post #27

I had a jr dev connect and typed 'flushall' because he thought it would refresh the dataset to disk. thankfully it was on a staging env, I think he's at google now.

One time during my internship years ago I took down a production server because of a command I ran on it that I didn’t fully understand. Since then I treat any prod server terminal like I’m entering launch codes for a middle system. Anything outside of ls or cd I’m very careful, read the command a couple times before executing, etc.

In my opinion you weren't at fault here. Production systems should be designed so that one person can't inadvertently destroy things.
Post reply on HN