The goal of “Riverdale,” according to creator and showrunner Roberto Aguirre-Sacasa, is always to push boundaries. After a second season that saw episodes take on the tone of “Zodiac” in a small town, “Tales From The Darkside,” and “The Godfather,” the CW’s dramatic adaptation of classic Archie Comics characters is getting musical.

“[Our characters] are kids who, even though they get involved in crime and stuff, are still high school kids — and high school kids do musicals every year,” Aguirre-Sacasa tells Variety. “So it feels like, on a show with high school kids, it’s easy to get to [a story where] we’re doing a musical. It’s one of the kind of classic coming-of-age rites of passage.”

Airing April 18, the episode entitled “Chapter Thirty-One: A Night To Remember” sees the students at Riverdale High — including Archie (KJ Apa), Betty (Lili Reinhart), Veronica (Camila Mendes), Kevin (Casey Cott) and Cheryl (Madelaine Petsch) — mounting a production of “Carrie: The Musical.” Meanwhile, Jughead (Cole Sprouse) acts as documentarian of the project.

The episode follows them, in sped-up time, as they go through rehearsals into opening night. And the singing is not relegated to the stage.

“We realized early on that going into the musical a lot of our [characters] were not on very friendly terms — there was a lot of tension between them — and one of the things that often happens in musicals is that people work out their emotional problems through song,” Aguirre-Sacasa says. “So I thought the musical episode could focus on the fractured friendships and help heal some of those and allow the songs to do some of the work.”

Here. Aguirre-Sacasa talks with Variety about the process of creating this musical episode, why it’s important that it moves the serialized story along rather than act as a standalone episode, and what other play the gang at Riverdale High almost performed instead.

What was the inspiration behind doing a musical episode, and how did you settle on “Carrie: The Musical” as the show-within-the-show?

The inspiration for the musical episode, on some level, was there was a high school production of “Sweeney Todd” in Australia maybe two years ago that we read about where a kid that was playing Sweeney Todd used the wrong prop razor and used a real razor and slit a kid’s throat. The kid survived, but it felt like such a “Riverdale” story! So originally we were like, “Let’s do ‘Sweeney Todd’ and let’s do that,” but then it evolved from there. Early on “Little Shop of Horrors” was [also in contention]. “Carrie” felt right because it was a little less well-known, it was a little more off-kilter the way “Riverdale” is, and it was about high school kids — the way “Riverdale” is — dealing with dark themes.

How do you feel the themes or characters of “Carrie: The Musical” best corresponded to what has been going on in “Riverdale”?

The thing about “Riverdale” and to a lesser extent but true as well about “Carrie” is both of them deal with archetypes. So you very quickly know what the archetype is. Betty is the quote-unquote good girl, and she’s playing Sue Snell, the good girl in “Carrie,” and Archie is the boy next door in “Riverdale” and he’s playing Tommy Ross, the boy next door in “Carrie.”

Is that also why you used Alice Cooper (Madchen Amick) in the school play, even though she’s neither teacher nor student?

Alice is a great character. Anytime we can do something with Alice it’s always good. Alice does have shades of Margaret White — Carrie’s mom — and it felt like a good echo. I think Margaret White loves Carrie but is sometimes very, very cruel to her, and I think Alice loves Betty but sometimes is very, very cruel to her. It’s more that they were similar and we could explore that in an interesting way. Margaret doesn’t want to let Carrie go to the prom but more so doesn’t want to let Carrie go, and I think Alice in this episode is afraid Betty will go the way everyone else seems to have gone. So it was story-driven. It’s almost always story-driven.

Where did Jughead come in? He seems like the kind of character who wouldn’t be into musicals, so did you ever consider just having him sit this out?

Absolutely. Jughead’s not really a musical theater guy, but he is very much an observer, so [using him as a documentarian] felt like a really good way to play that.

What did you want the documentary angle to add to the story?

Usually kids rehearse the musical over weeks and then put it on. We wanted to start with the rehearsal process and then end on opening night [and] it’s hard to tell a linear story like that in 41 minutes of television. So the idea of doing a documentary allowed us to be a little more nimble and jump around a little more.

With “Carrie: The Musical” being not as well-known, did that pose any additional challenges in how to adapt it for the screen?

‘ve known about “Carrie: The Musical” for 25 years, I wrote the “Carrie” remake, I had a really clear idea of what the show would look like. …Basically we sat in the writers’ room and listened to the score and the cast album and then kind of said, ‘Oh this song could be good for this’ or ‘This song could be good for that.’ We were lucky that things lined up as well as they did, and that’s kind of what helped us decide which songs to do. In my mind the best musicals [have] songs that continue the story or reveal the character, and characters begin the song in one place and end someplace else.

How important was it to craft a story that wasn’t just a standalone for one episode?

If we couldn’t have figured out that, we wouldn’t have done the episode. Because we’re so late in the season and once you’re so serialized, it’s hard to step out of that and forget what you’re going through. That said, I would say that the musical episode does focus a little bit more on character and emotion rather than huge, complicated, intricate plots. We did adapt our storytelling to be a little more emotional and a little less intricate, and I think that really, really helped.

Along those lines, Cheryl just went through something very traumatic, having been sent away for conversion therapy, yet she immediately said she wanted to be in this play upon her return.

Anytime you can find an emotional reason for why a character’s doing something, it’s always better. Cheryl’s a character who can basically do anything she wants because of who she is, but when you think about the reason that Cheryl wants to be the lead in the music is to prove to the town that she wasn’t broken by what her mother’s done over the last few weeks, then that story takes a deeper resonance. So, you always try to find those deeper underpinnings.

What were you looking for from the director of the episode and how did that lead you to choosing Jason Stone for the gig?

We got very lucky that Jason was the director. We booked Jason for this episode slot before we knew it was going to be the musical episode. But Jason has boundless energy and is not afraid of anything [which was good because] we didn’t have any extra prep time. We did this huge production in the same amount of time it takes to do a normal episode of “Riverdale.” You’ve got to produce the show that you produce every week and then you’ve also got to produce the show that they’re [mounting].

Would you do a musical episode again?

We would absolutely do a musical again. Every high school does a musical every year. So I think it would be finding the right [one]. We got really lucky — “Carrie” felt like it slotted in perfectly and these stories felt like they docked perfectly. The bar is really high but 100% we would do it again. I think everybody had a blast doing it.

Watch the cast of “Riverdale” perform “A Night We’ll Never Forget” below:

“Riverdale” airs Wednesdays at 8 p.m. on the CW.