How does google ads work such that it delivers the right ad in 50ms?

How does google ads work such that it delivers the right ad in 50ms?