My fiancé was out of town, our spare key was sitting in the junk drawer inside our apartment, all the windows were either locked or inaccessible and our landlord was hours away. Besides breaking a window (a serious consideration) a locksmith was my only hope.
After hours of lock picking and bump keys on both the front and back door the locksmith presented me with good news - it's really hard to break into our apartment, which was also the bad news. My misfortune might have been related to the inadequate abilities of the locksmith, either way, two hours into the endeavor I was committed. Eventually, he drilled the lock and was able to break through. Hallelujah!
I wouldn't wish this experience on anyone. To avoid the trauma, make a plan for a spare key. Your safest bet is to give a spare to a friend or family member nearby, however, this isn't a foolproof method if that person happens to be out of town when you lock yourself out. The alternative, yet less safe option, is to hide a key somewhere outside of your apartment. Another way to avoid a lock-out is to get in the habit of dead-bolting the door from the outside. This will force you not to leave your keys inside. These are all best practices I now plan on practicing.
What's your back-up plan?