Database + Queue: Getting the Semantics Right

We often have a pattern of database writes combined with a message queue. But ensuring correctness is hard.