Don’t put yourself in this situation! The people who will be writing letters for you are very busy individuals and they often forget to write a letter of recommendation. The worst thing to do is to remind them last minute since at this point they will rush a letter all while being under pressure by the student.
The following time guideline, two-two-two, is highly recommended so that you do not find yourself such a situation. Give the person enough time so they can comfortably write a letter for you in their free time. I recommend asking them two months before the letter is needed. This way they have no reason to feel pressured. Since you are asking two months in advance, two weeks prior to the deadline, contact the individual and remind them of the letter of recommendation and see if they need any other documents or information from you. The final component of this plan is to give them a deadline that is two weeks before the actual due date. This will give you an extra window of time just in case they do not finish it on time for any reason. At this point, you can tell them that the latest the school will take it is two weeks from the deadline and that you would really appreciate if they could still write the letter for you. Following this procedure will minimize the stress on both of you and since a two month window was given, the recommended should not have any reason to think negatively about you if the letter sees any unforeseeable delays.