I've been doing a lot of thought on replication setup and some of the problems with single backup servers and synchronous replication. Does anybody here know the order in which writes (updates) are passed in a master server?

What I'm asking is: does the WAL get written out, prior to the actual data commit in the database or is the WAL written after the fact?

I'm thinking that if it was before, and that WAL write took place on a system other than the master, say on the backup server as specified in the setup docs, then I really don't see how the system could experience data loss. If the WAL write was after the db write, then sure, the backup could possibly not get the most recent update. Otherwise, the only failure mode I can envision is that the last entry got corrupted and might be unreadable due to the master crashing, but that should be OK since the master couldn't have written the data to the db either.

Am I advocating for the destruction of the universe as we know it or have I missed something major?