Your leavening agents (baking soda, baking powder) should help prevent this. If you’re getting flat cookies check the date on your leavening agents to make sure they’re not expired. Another solution is chilling your dough. This chills the butter, so your cookies won't spread as rapidly in the oven during baking.