Simultaneous work on the same document

Simultaneous work on the same document

If several clients modify the same document at the same time. How does the system know which version to stay with?