The serving side serves from the right service court when its score is even, and from the left service court when its score is odd.
At the start of a game, the score is 0-0, so the first serve is from the right service court.
Only the player in the correct court serves, and the receiver stands diagonally opposite.
The two partners of the serving side change service courts only when they win a point while serving. The same player keeps serving, now from the other court.
The receiving side never changes courts when it loses a rally. Its players stay where they are.
Example
A and B play against C and D. A serves from the right and wins the rally: score 1-0, A and B swap, A serves from the left to whoever stands there on the other side.
When the serving side loses a rally, the serve goes to the other side. The serve then moves from player to player in a fixed order. No player may serve or receive out of turn, and a player may not receive two serves in a row.
The player who serves is always the one standing in the court that matches the side's score.
If someone serves or receives out of turn or from the wrong court, it is corrected and the score stays the same.
The umpire or players can point out the mistake. But if the mistake is found only after the next serve was made, the error is not corrected, and play continues with the current positions.
Doubles pairs should check the score before every serve, so mistakes are rare at top level.
At the start of a game, the side that serves first chooses which player serves. The side that receives chooses which player receives.
After that, the order follows the score and who won the last point.
When the serving side's score is even, the serving player stands in the right court; when it is odd, in the left court.
The receiving player is always the one diagonally opposite. If the serve comes back to a side, the player in the correct court receives.
Sources