Haproxy use backend server based on past response status

How can i configure haproxy to use backendserver based on past response status codes. For example if response code for backendserver A is for host www.google.com is 503 and for backendserver B is 200 than haproxy should use in future requests backendserver B instead of A.

Look into the observe layer7 option (documentation here).

For example, something like

server [...] observe layer7 error-limit 3 on-error mark-down

This would mark the backend server as down after 3 503 errors (and you need another “normal” health check to mark the server up again when it becomes available)

Thanks for reply, how can i tell haproxy to not use backend if response time is slow.