I'd put the logic in the browser. You're already using Ajax, so Javascript is already enabled.
It could go something like this.
- The user composes a request (webform?) and sends it to your server by Ajax.
- Your CGI script check how long it has been since a request has been sent to a particular server. If it's been less than 10 seconds (or there are other people in the queue) give back a negative response to the browser via the Ajax response, together with an estimate of how much time it should wait before retrying.
- You might also keep a queue for each server, and pass back the queue position to the user, but you'd have to take into account that some users will not wait, so the queue might actually move faster than the first estimate. I'd have the server wait up to 2 seconds for a retry by the user, before moving on to the next person in the queue.
- The browser can then alert the user of the wait time, wait for the indicated time, and try again (with window.setTimeout).
- If the person is the first in the queue, service the request and return a positive answer.