How do book publishing deals work?

Usually, the writer has an agent. The agent will find a publisher who wants to buy the book. The writer will sign a contract agreeing to sell different rights to the publisher (usually First North American Rights, which means they can publish it the first time in North America) and is paid a flat fee for this. They can also get royalties later if the books sell really well - this is a percentage of the profit. Oh, and the agent gets paid a percentage of the fees for all their hard work finding the publisher.
Remember, each type of right that a writer sells means money for them, so you don't want to sign away all your rights to the publisher at once -- they will need to renegotiate for rights in foreign countries, for e-book rights, for movie rights, etc.
Usually, the writer has an agent. The agent will find a publisher who wants to buy the book. The writer will sign a contract agreeing to sell different rights to the publisher (usually First North American Rights, which means they can publish it the first time in North America) and is paid a flat fee for this. They can also get royalties later if the books sell really well - this is a percentage of the profit. Oh, and the agent gets paid a percentage of the fees for all their hard work finding the publisher.
Remember, each type of right that a writer sells means money for them, so you don't want to sign away all your rights to the publisher at once -- they will need to renegotiate for rights in foreign countries, for e-book rights, for movie rights, etc.