The authorities recommend at least 72 hours in advance. However, if you plan to visit the USA, it is advisable to apply as early as possible. If your travel authorization is denied, you must apply for a visitor’s visa at a U.S. embassy or consulate. Sometimes appointments are difficult to reach and can take weeks.
It is also possible that the system may be subject to temporary maintenance. In this case, both the application and the decision on your ESTA application may take longer than is usually the case. In addition, the US authority may have further questions about your case or may consider it for a longer period of time. There is therefore no guarantee that you will receive your ESTA within a few minutes or hours, even if this is normally the case.
Please remember that you are not allowed to board the plane to the USA if you do not have a valid ESTA. Your flight ticket alone is not sufficient and you will not normally be reimbursed for the missed flight. It is therefore worth taking care of the ESTA application in good time.