The vast majority of ESTA applications are done instantly. It can take up to 72 hours and that is why they advise giving at least that amount of time between application and travel.
Behind the scenes the TSA / DHS are doing some very clever mathematics with your application. They do similar modelling every time you travel to the US to calculate the probability you pose a security or immigration risk to the country. I was on a flight back from the US two weeks ago and onboard were a couple who, despite having used their ESTA a few times before, were refused entry the same day they were returned. Why? Who knows, but having strange open jaws going back from Canada can't have helped.