SAN FRANCISCO — There's a certain formula to the Twitter-fueled fall from grace.

Someone finds old, offensive tweets from a public figure and begins resurfacing them. The tweets get the attention of people who begin to shame the person in question. News outlets begin to pick up on the shaming. The situation snowballs until someone acts.

At minimum, the public figure says they're embarrassed and apologizes. At most, the old tweets ruin a career and a reputation.

Three major league baseball players apologized last week after racist and homophobic tweets they sent in high school were exposed. Roseanne Barr had been no stranger to trouble on Twitter, but a racist tweet about Obama adviser Valerie Jarrett ultimately led to the cancellation of her show, "Roseanne."

And most recently, journalist Sarah Jeong was in the spotlight this week after some of her old, inflammatory tweets about race were resurfaced. The technology reporter, who is joining The New York Times editorial board, said she was responding to trolls using satire. The uproar was big enough to prompt a response from the Times, which said it doesn't condone how Jeong responded to trolls but stands by her hiring.

But in an era where politically divisive conspiracy theories attract legions of followers and fodder on social media, old tweets are being used as a weapon to take down anyone seen as the opposition.

James Gunn was fired as director of "Guardians of the Galaxy Vol. 3" after Twitter users discovered old tweets from years ago in which he made light of pedophilia and rape. The tweets were spotlighted by the alt-right, including far-right agitator Mike Cernovich. Gunn apologized and the cast shared an open letter asking Disney to reinstate Gunn as director of the movie.

Dan Harmon, the co-creator of "Rick and Morty," left social media after an offensive decade-old sketch, which he later apologized for, caught the attention of the alt-right on 4chan and The_Donald subreddit.

But the ghosts of Twitter past can also come back to haunt anyone and these are just a few of many cautionary tales. While nothing is truly gone forever on the internet, there are some precautions people can take now to clean up their embarrassing old tweets.

Third-party services can act as a Twitter cleaning crew

There are a number of third-party services that can help tidy up a person's Twitter profile, either for free or at the cost of a few dollars. Twitter does not offer any way to mass-delete tweets.

TweetDelete allows users to decide how far back they want to delete their tweets. Users can also choose an option to set an expiration date for tweets that are, say, more than one week old, sending them off into the great online abyss.

For around the price of a fancy coffee, TweetDeleter and TweetEraser will help you filter and delete your tweets in bulk, so you don't have to do it by hand. You can also archive your tweets for private viewing, in case you don't want to lose any of those gems from years ago.

Target tweets by searching your archive

Users who think they're pretty clean or don't want to engage a third-party service can always do a quick manual search and delete any particular tweets they find.

This can be done by going to Twitter's search bar and typing in your Twitter handle and a keyword. Once the tweet has been located, click the arrow in the upper right corner and then click "delete tweet."

Start completely fresh

It's possible to delete tweets, but with various sites and search engines indexing social media sites, nothing can truly ever disappear from the internet.

However, for users looking for a fresh start, deactivation is one option. From account settings, users can choose "deactivate my account." They'll be asked to make sure they really, really want to do that before Twitter takes action.

Twitter will retain the data for up to 30 days, during which time, Twitter will honor any second thoughts and let users reactivate their accounts.

Of course, instead of going through all this trouble, there is one way to make it easy— just don't tweet anything you wouldn't want your grandma or your boss to see.