This week, after a new, activism-themed ad from Pepsi fizzled when it was met with backlash on social media, the late-night host Jimmy Kimmel told his audience, "The fact that this somehow made it through—I can't imagine how many meetings, and edits, and pitches, and then got the thumbs-up from who-knows-how-many people is absolutely mind-boggling.”

With one marketing firm estimating that at one point this week, roughly three-quarters of social-media engagement around the phrase “tone-deaf” mentioned Pepsi or the ad’s star, the 21-year-old model Kendall Jenner, Kimmel was articulating a widespread bafflement: How does a company—a major global brand worth more than $150 billion—make a multimillion-dollar advertisement that it later has to pull, conceding that it had “clearly missed the mark”? How could a bunch of well-paid, supposedly zeitgeist-fluent copywriters, art directors, and marketing executives have agreed that, indeed, the message the company should put out into the world is that the soda they were promoting is what can bring the country together at a fractious time?

The specifics of an answer may never be made public—I received no response after asking Pepsi about it—but it’s not as if the process for producing an ad like Pepsi’s is an unknowable mystery. Based on conversations and email exchanges I had with marketing professors and people who work in the advertising industry, it’s possible to piece together what goes into making a costly, celebrity-featuring ad like the one Pepsi put out—who made which decisions, and when. The advertising experts I talked to identified some of the pitfalls that can arise in such a process, which some of them estimated might have lasted around six to eight months, cost several millions of dollars, and involved somewhere between 20 and 50 people.

Most likely, the roots of a big, production-heavy ad like the one Pepsi released this week could be traced back to a research report, possibly one published internally a bit longer than six to eight months ago. Before anyone starts brainstorming concepts for an ad, there’s usually some sort of research-based conclusion that the copywriters are acting on. For example, there could be internal data suggesting that Millennials are a prime target for an ad, and that one of the things that resonates most with Millennials is activism. Recently, advertisers’ confidence in social-justice-oriented campaigns might have been propped up by high-profile Super Bowl ads that successfully broached politically-charged topics.

So, well before any models present cans of soda to police officers on camera, the message of an ad has in many ways already been decided. As Schuyler Vanden Bergh, a creative director at the San Diego-based agency The i.d.e.a. Brand, told me, “This is where the misstep usually happens … ‘We want to attract millennials, they're activists'—that kind of heads you down a certain path."

Arising from these research reports is the creative brief, a document containing a big-picture vision of what the brand should stand for in the ad. This is where the six-to-eight-month timeline kicks off. (The timeline can be shorter for spots that are smaller in duration and scope.) A brief might suggest ways in which a new campaign could be a continuation of themes raised in older ones. Pepsi, for instance, has a history of adeptly tapping into youth culture, starting with its successful “Choice of a New Generation” campaign in the ‘80s. But Aimee Drolet Rossi, a professor of marketing at UCLA’s School of Management, suggested to me that Pepsi in this case might have adhered too much to its past. She notes that the Kendall Jenner spot featured the hallmarks of a Pepsi ad: celebrities (the brand in the past has deployed Michael Jackson and Beyoncé) and young people. “It seems like in a way they were going through the motions of how they typically market the product,” she says.

Once a broad vision for the ad is in place, it’s time to start letting the “creatives”—the people who conceptualize the visuals for and actually write the ads—dream up the details. Often, the creatives work in teams of two, each team consisting of a copywriter and an art director. They get together and brainstorm ideas, perhaps for a month or so, and then present them to the project’s creative director, who oversees all of the teams. The creative director nixes some ideas and selects others to be developed further over the next couple of weeks. After some refining, those ideas are presented again, the creative director selects his or her favorite, and then he or she shares it with everyone at the agency and gathers feedback.

It is by the end of this stage that an inadvertently offensive ad hopefully has gotten flagged as such. Many creative directors studiously analyze all of the ways an ad could be interpreted, looking out for things that could unintentionally provoke ire. However, as is evidenced by instances such as the maligned Budweiser campaign that suggested the beer would succeed in “removing ‘no’ from your vocabulary,” this doesn’t always happen. Why? Sometimes it’s because ad agencies aren’t sufficiently aware of what could set off a cultural backlash. This is something that frequently comes up when advertisers court young consumers. “My theory is that the creators were significantly older than the target audience and did not understand the Millennial market,” says Bruce Vanden Bergh, a professor of communication at Michigan State University (and, coincidentally, Schuyler Vanden Bergh’s father). Further, with Pepsi, it has been reported by the British tabloid The Daily Mirror that the team of six people at the company’s in-house agency who oversaw the ad were all white.

Once the agency is pleased with a concept, it makes a presentation to the client. After some back-and-forth, the two parties arrive at a final script for the spot. Meanwhile, as all of this has been unfolding, various other marketing teams have been active as well. There is a media team, whose job it is to figure out the best place—a Google ad buy? TV?—to get the message out to. And there is also a team putting out feelers to potential celebrity endorsers. Stars, when approached, get a good sense of the ads they’ll be appearing in, and make a decision to participate based on whether the ad aligns with their brand and how sweet the deal is. Record labels and musicians, who have similar calculations to make, might also be presented with offers to license their music as a soundtrack for the spot.

Once a script is set and the agency and client are in agreement, a producer steps in. It’s the producer’s job to execute the spot. Their first task is taking care of the pre-production work—reaching out to potential directors, hiring one of them, and taking care of all the logistical details of a shoot—which can take about three or four weeks. And then, there’s the shoot itself. For a spot like Pepsi’s, which clocked in at around two-and-a-half minutes but appeared to be filmed at a single location, the shoot might be a full 10- or 12-hour day. (This can vary depending on how long the spot is and how many locations are involved.) Once the shoot wraps, it’s another month or two of post-production work—the fine-tuning of the ad’s appearance, sound, and pacing. During this period, ads are sometimes shown to focus groups, which aside from being a chance to gauge an ad’s effectiveness is another opportunity for a company to identify a potentially offensive spot. If all goes smoothly, the ad is released out into the world.

After Pepsi released its ad out into the world, many social-media reactions were tongue-in-cheek offers from non-advertising-experts to “consult” for Pepsi, by reviewing its ads and telling the company which ones are offensive. I asked Schuyler Vanden Bergh, the creative director, whether these people actually had a point, or if they were being glib about an ad-production process whose complexity they do not grasp. “I think it’s really that simple,” he said, adding, "If there were 50 people involved, I'd imagine there was one person that [had doubts], and—I don’t know if they were a junior person, I don’t know if they were a senior person, I don’t know what they were—but they didn’t feel comfortable speaking up in that room. Or maybe they did, and they were outvoted."

Still, there are some other, more nuanced dynamics that the advertising experts I talked to brought up when I asked them for theories about how an out-of-touch ad comes to exist.

“How do these ads get approved?,” Jill Avery, a senior lecturer at Harvard Business School, wrote me in an email. “By brand managers who are not doing their cultural homework—relying upon surface-level understandings of the cultural phenomenon they are featuring in their marketing communications and not understanding the deep well of emotions, identity politics, and ideologies that their ads will trigger.” She also said that campaigns can be imperiled when a company chooses to link its product to a social message that may not be part of its corporate mission.

Schuyler Vanden Bergh brought up a smaller point specific to the Pepsi ad. He noted that the ad was produced not by an outside agency but rather Pepsi’s in-house Creators League studio. “What happens sometimes with an in-house agency, and I think maybe that happened here,” he says, “is … they’re too inside, too close to the product.” Vanden Bergh was quick to acknowledge that he himself works for an agency and might be biased about the advantages of working with one. And even though outside ad agencies have surely produced their share of offensive ads, his point still stands. As more companies experiment with faster-moving, more cost-effective in-house agencies, it’s more likely that an ad won’t be exposed to enough people outside a single company’s culture.

But working with outside agencies can present its own problems. For one thing, agencies must compete against one another to earn clients’ business, which can generate high-quality work but also some less-than-ideal outcomes. Drolet Rossi, the UCLA professor, says that for big-deal spots like Super Bowl ads, the tight competition among agencies can lead them to be too ambitious in their proposals, which can backfire when those ads are actually produced.

Drolet Rossi left me with a parting thought about how much an ad like Pepsi’s actually hurts the company. She suggested that some of the company’s suffering was overblown, saying, “There's a lot of outrage, but who's being outraged? Is it in fact the people that are interested in buying Pepsi products? Pepsi targets teens—they’re young teens, because soda preferences tend to be fixed by the time you get a little older, so if they lock you in early, they kind of capture you. Then you have to ask yourself, from the perspective of a 13-year-old or a 12-year-old, which is their target: How tone-deaf and out-of-touch does it seem?"

It may then be the case, as my colleague Ian Bogost suggested earlier this week, that the Pepsi ad was not a failure but a major success. In addition to thrilling the target audience that Drolet Rossi identified, it—from its release to its high-profile retraction—kept consumers’ attention on the Pepsi brand. If this is how any Pepsi executives come to see this week’s events, maybe it’s not ultimately all that baffling that history provides so many examples of backlash-producing, attention-grabbing ads.