Writing the database before replying costs a round trip and a disk commit; replying first is faster, but the write lives only in cache memory until it is flushed.
Learn the idea first
An admin changes product 42's price from $20 to $18. The app server keeps a copy in a cache (memory) and the record in a database (disk). The toggle decides whether the database is written before or after the reply. Timings are an illustrative model.
App server
handles the price change
Cache
in memory
Database
on disk
Swipe the diagram sideways to see every column →
Where the time goes
5 ms total
An admin changes product 42's price from $20 to $18. The app server keeps a copy in a cache (memory) and the record in a database (disk). The toggle decides whether the database is written before or after the reply. Timings are an illustrative model.
Illustrative timings. Real numbers vary with distance, network quality and server load.