Often built from leftover ingredients, deeply caramelized and married with bold seasonings, nasi goreng is a kitchen sink sort of dish that manages to cross the many cuisines and cultures of Indonesia’s more than 17,000 islands.

And as we tried to create our own version, we learned that while most anything might go, achieving its distinctive and delicious blend of savory-sweet flavors and tender-crisp textures required we learn when to step away from the stove.

At its most basic, nasi goreng is day-old rice seasoned with aromatics, chilies, kecap manis—a savory-sweet dark soy sauce rich with palm sugar—and funky shrimp paste, all stir-fried until richly caramelized. And in Indonesia, there isn’t a home, village, restaurant or street cart without its own take on it, says Lara Lee, author of “Coconut & Sambal: Recipes from my Indonesian Kitchen.”

Depending on where you are along the archipelagic state, nasi goreng could be made with pork, seafood or fresh vegetables. And Jakarta’s street-food vendors famously throw in everything left over at the end of the night.

Our first challenge was approximating the flavor, which is built largely from two ingredients that can be hard to find in the U.S.—kecap manis and shrimp paste. For the former, we opted for a combination of regular soy sauce and brown sugar, which has malty notes similar to palm sugar. For the latter, we substituted fish sauce to add deep umami notes.

After that, it was all about timing. When ingredients are added to the pan—and what you do to them once they are in—turned out to matter greatly. Classic nasi goreng has an appealing browned richness best achieved by caramelizing ingredients in stages.

Chicken and aromatics go first, giving them time to sear and develop flavor. Then the rice—day-old is essential, as its texture remains light when stir-fried—is added. That’s when the stirring stops. Three to four minutes like this allows the rice to crisp a bit on the bottom of the pan.

Only then are the seasonings added—sooner and it could inhibit the crisping of the rice. The sugars caramelize for even deeper flavor. The result—topped as is traditional with a crispy fried egg—achieves the perfect blend of tastes and textures.