|  | 
| 1 | 1 | --- | 
| 2 |  | -Title: Use the WAIT command for strong consistency | 
|  | 2 | +Title: Use the WAIT command to improve data safety and durability | 
| 3 | 3 | alwaysopen: false | 
| 4 | 4 | categories: | 
| 5 | 5 | - docs | 
| 6 | 6 | - operate | 
| 7 | 7 | - rs | 
| 8 | 8 | description: Use the wait command to take full advantage of Redis Enterprise Software's | 
| 9 |  | -  replication based durability. | 
|  | 9 | +  replication-based durability. | 
| 10 | 10 | linkTitle: WAIT command | 
| 11 | 11 | weight: $weight | 
| 12 | 12 | --- | 
| 13 | 13 | Redis Enterprise Software comes with the ability to replicate data | 
| 14 | 14 | to another replica for high availability and persist in-memory data on | 
| 15 |  | -disk permanently for durability. With the WAIT command, you can | 
|  | 15 | +disk permanently for durability. With the [`WAIT`]({{<relref "/commands/wait">}}) command, you can | 
| 16 | 16 | control the consistency and durability guarantees for the replicated and | 
| 17 | 17 | persisted database. | 
| 18 | 18 | 
 | 
| 19 |  | -Any updates that are issued to the database are typically performed with | 
| 20 |  | -the following flow shown below; | 
|  | 19 | +## Non-blocking Redis write operation | 
| 21 | 20 | 
 | 
| 22 |  | -1. Application issues a write, | 
| 23 |  | -1. Proxy communicates with the correct master "shard" in the system | 
| 24 |  | -    that contains the given key, | 
| 25 |  | -1. The acknowledgment is sent to proxy once the write operation | 
| 26 |  | -    completes | 
|  | 21 | +Any updates that are issued to the database are typically performed with the following flow: | 
|  | 22 | + | 
|  | 23 | +1. Application issues a write. | 
|  | 24 | +1. Proxy communicates with the correct primary shard in the system that contains the given key. | 
|  | 25 | +1. The acknowledgment is sent to proxy after the write operation completes. | 
| 27 | 26 | 1. The proxy sends the acknowledgment back to the application. | 
| 28 | 27 | 
 | 
| 29 |  | -Independently, the write is communicated from master to replica and | 
| 30 |  | -replication acknowledges the write back to the master. These are steps 5 | 
| 31 |  | -and 6. | 
|  | 28 | +Independently, the write is communicated from the primary shard to the replica, and | 
|  | 29 | +replication acknowledges the write back to the primary shard. These are steps 5 and 6. | 
| 32 | 30 | 
 | 
| 33 | 31 | Independently, the write to a replica is also persisted to disk and | 
| 34 | 32 | acknowledged within the replica. These are steps 7 and 8. | 
| 35 | 33 | 
 | 
| 36 | 34 | {{< image filename="/images/rs/weak-consistency.png" >}} | 
| 37 | 35 | 
 | 
| 38 |  | -With the WAIT command, applications can ask to wait for | 
|  | 36 | +## Blocking write operation on replication | 
|  | 37 | + | 
|  | 38 | +With the `WAIT` command, applications can ask to wait for | 
| 39 | 39 | acknowledgments only after replication or persistence is confirmed on | 
| 40 |  | -the replica. The flow of a write operation with the WAIT command is | 
| 41 |  | -shown below: | 
| 42 |  | - | 
| 43 |  | -1. Application issues a write, | 
| 44 |  | -1. Proxy communicates with the correct master "shard" in the system | 
| 45 |  | -    that contains the given key, | 
| 46 |  | -1. Replication communicated the update to the replica shard. | 
| 47 |  | -1. Replica persists the update to disk (assuming AOF every write setting | 
| 48 |  | -    is selected). | 
| 49 |  | -1. The acknowledgment is sent back from the replica all the way to the | 
| 50 |  | -    proxy with steps 5 to 8. | 
|  | 40 | +the replica. The flow of a write operation with the WAIT command is: | 
|  | 41 | + | 
|  | 42 | +1. The application issues a write, | 
|  | 43 | +1. The proxy communicates with the correct primary shard in the system that contains the given key, | 
|  | 44 | +1. Replication communicates the update to the replica shard. | 
|  | 45 | +1. The replica persists the update to disk if the AOF every write setting is selected. | 
|  | 46 | +1. The acknowledgment is sent back from the replica all the way to the proxy with steps 5 to 8. | 
| 51 | 47 | 
 | 
| 52 | 48 | With this flow, the application only gets the acknowledgment from the | 
| 53 | 49 | write after durability is achieved with replication to the replica and to | 
| 54 | 50 | the persistent storage. | 
| 55 | 51 | 
 | 
| 56 | 52 | {{< image filename="/images/rs/strong-consistency.png" >}} | 
| 57 | 53 | 
 | 
| 58 |  | -With the WAIT command, applications can have a guarantee that even under | 
| 59 |  | -a node failure or node restart, an acknowledged write is recorded. | 
|  | 54 | +The `WAIT` command always returns the number of replicas that acknowledged the write commands sent by the current client before the `WAIT` command, both in the case where the specified number of replicas are reached, or when the timeout is reached. In Redis Enterprise Software, the number of replicas is always 1 for databases with high availability enabled. | 
| 60 | 55 | 
 | 
| 61 |  | -See the WAIT command for details on the new durability and | 
| 62 |  | -consistency options. | 
|  | 56 | +See the [`WAITAOF`]({{<relref "/commands/waitaof">}}) command for details for enhanced data safety and durability capabilities introduced with Redis 7.2. | 
0 commit comments