Baseball is said to be a game of failure. Running a baseball team often is an exercise in managing failure.

Free agents are unpredictable. Trades are risky. Player development is arduous. Anything from an injury to a petty clubhouse rift can ruin a season.

Being a major league CBO or GM is a difficult and relentless job. Or so we thought.

The Twins begin a homestand Friday with baseball’s best record. While previous regimes deserve credit for amassing young talent, the current Twins front office had an offseason for the ages, one belying the difficulty of roster management.

They hired Rocco Baldelli as manager. His record on the job is 23-12. “Rocco has been everything we hoped he would be as a leader, in terms of building relationships and leading the staff,” Derek Falvey, Twins chief baseball officer, said Thursday.

They hired pitching coach Wes Johnson. Johnson overhauled the pitching mechanics of Jake Odorizzi and Martin Perez. Odorizzi, who had a 4.49 ERA last year, has a 2.78 ERA this year. Perez, who had a 4.54 ERA for his career and a 6.22 ERA last year, has a 2.83 ERA this year.

“I know a lot was made about him coming out of college and the uniqueness of that,” Falvey said. “The thing I knew about Wes going in is that this guy is super prepared. He loves pitching more than anyone I’ve been around, and I consider myself someone who loves pitching. I would put him in a class by himself.”

The Twins took the $23 million they had been paying Joe Mauer, added a few million and used the money to sign DH Nelson Cruz, first baseman C.J. Cron and second baseman Jonathan Schoop. Last year, with Miguel Sano in the big leagues, they ranked 23rd in home runs. This year, without Sano, they rank fourth.

In Cruz, they landed a No. 3 hitter and a clubhouse leader, at $9 million less than they were paying Mauer. “We tapped into so many people to understand the backgrounds and makeup of our external acquisitions,” Falvey said. “To a man, each of them have been everything they were advertised to be. They are all real quality people.”

The Twins signed Marwin Gonzalez, and while he hasn’t hit to expectations, his glove and versatility have helped the Twins survive Sano’s injury. They got Perez for $3.5 million and reliever Blake Parker for $1.8 million — meaning they’ll pay one of their top starters and one of their endgame relievers less this year, combined, than they’re paying Phil Hughes.

They signed Max Kepler and Jorge Polanco to five-year contract extensions in February, even though Kepler was coming off a mediocre season and Polanco a PED suspension. Polanco is hitting .344 and Kepler has seven homers and an .816 on base-plus-slugging percentage.

“They are really good, quality young players who weren’t at a full level of maturity yet,” Falvey said. “We were fortunate they wanted to engage in a conversation about a long-term fit. Sometimes, those contracts allow young guys to be free and just go play.”

The most popular word in sports these days is “analytics.” Listen to Falvey, and you think that the better-if-blander words for the Twins’ approach are “exhaustive research.”

They have invested heavily in modern analytics and analysis. They also tapped into General Manager Thad Levine’s relationships with Cruz and Perez, their traditional scouts, their analytics department and anyone who could offer insight or information on a pitcher’s velocity or temperament.

“For every one of these guys, there’s a unique story and a unique history that you want to understand,” Falvey said.

With the Twins seemingly headed for the postseason, the fan base has already begun demanding flashy moves. Parker and Taylor Rogers are perfect in save opportunities, but fans want Craig Kimbrel, whose postseason ERA the past three years is 5.68 and whose ERA the second half of last season was 4.57.

Fans crave midseason acquisitions. They shouldn’t let the theoretical miracle on the horizon distract from the miracles that have already occurred for the team with the best record in baseball.