The short answer: You resolve effects on the stack one at a time, and everyone gets a chance to put new stuff on the stack before you resolve the next effect.
More detailed answer: The Magic comp rules use a system called "priority" to determine when you have a chance to play abilities and put stuff on the stack. Generally speaking, you can always respond to an event that changes the game state, but players get to do so in a defined order.
For our shared convenience,I'm going to blockquote all of section 116, Timing and Priority, and then mark the critical parts in bold.
116. Timing and Priority
116.1. Unless a spell or ability is instructing a player to take an action, which player can take actions at
any given time is determined by a system of priority. The player with priority may cast spells,
activate abilities, and take special actions.
116.1a A player may cast an instant spell any time he or she has priority. A player may cast a
noninstant spell during his or her main phase any time he or she has priority and the stack is
116.1b A player may activate an activated ability any time he or she has priority.
116.1c A player may take some special actions any time he or she has priority. A player may take
other special actions during his or her main phase any time he or she has priority and the stack is
empty. See rule 115, “Special Actions.”
116.1d A player may activate a mana ability whenever he or she has priority, whenever he or she is
casting a spell or activating an ability that requires a mana payment, or whenever a rule or effect
asks for a mana payment (even in the middle of casting or resolving a spell or activating or
resolving an ability).
116.2. Other kinds of abilities and actions are automatically generated or performed by the game rules,
or are performed by players without receiving priority.
116.2a Triggered abilities can trigger at any time, including while a spell is being cast, an ability is
being activated, or a spell or ability is resolving. (See rule 603, “Handling Triggered Abilities.”)
However, nothing actually happens at the time an ability triggers. Each time a player would
receive priority, each ability that has triggered but hasn’t yet been put on the stack is put on the
stack. See rule 116.5.
116.2b Static abilities continuously affect the game. Priority doesn’t apply to them. (See rule 604,
“Handling Static Abilities,” and rule 611, “Continuous Effects.”)
116.2c Turn-based actions happen automatically when certain steps or phases begin. They’re dealt
with before a player would receive priority. See rule 116.3a. Turn-based actions also happen
automatically when each step and phase ends; no player receives priority afterward. See rule
703, “Turn-Based Actions.”
116.2d State-based actions happen automatically when certain conditions are met. See rule 704.
They’re dealt with before a player would receive priority. See rule 116.5.
116.2e Resolving spells and abilities may instruct players to make choices or take actions, or may
allow players to activate mana abilities. Even if a player is doing so, no player has priority while
a spell or ability is resolving. See rule 608, “Resolving Spells and Abilities.”
116.3. Which player has priority is determined by the following rules:
116.3a The active player receives priority at the beginning of most steps and phases, after any turn-
based actions (such as drawing a card during the draw step; see rule 703) have been dealt with
and abilities that trigger at the beginning of that phase or step have been put on the stack. No
player receives priority during the untap step. Players usually don’t get priority during the
cleanup step (see rule 514.3).
116.3b The active player receives priority after a spell or ability (other than a mana ability) resolves.
116.3c If a player has priority when he or she casts a spell, activates an ability, or takes a special
action, that player receives priority afterward.
116.3d If a player has priority and chooses not to take any actions, that player passes. If any mana is
in that player’s mana pool, he or she announces what mana is there. Then the next player in turn
order receives priority.
116.4. If all players pass in succession (that is, if all players pass without taking any actions in between passing), the spell or
ability on top of the stack resolves or, if the stack is empty, the
phase or step ends.
116.5. Each time a player would get priority, the game first performs all applicable state-based actions as a single event (see rule 704,
“State-Based Actions”), then repeats this process until no state-based
actions are performed. Then triggered abilities are put on the stack
(see rule 603, “Handling Triggered Abilities”). These steps repeat
in order until no further state-based actions are performed and no
abilities trigger. Then the player who would have received priority
116.6. In a multiplayer game using the shared team turns option, teams rather than individual players have priority. See rule 805, “Shared
Team Turns Option.”
116.7. If a player with priority casts a spell or activates an activated ability while another spell or ability is already on the
stack, the new spell or ability has been cast or activated “in
response to” the earlier spell or ability. The new spell or ability
will resolve first. See rule 608, “Resolving Spells and Abilities.”
How about an example?
Alice and Bob are playing. They're trying to brush up on technical play, so they're making sure to follow each little step in order to be ready for tournaments and judges.
It is Alice's main phase.
As the active player, Alice has priority.
Alice casts Fireball. She moves the card from her hand to the stack for all players to see. She determines the parameters (the value of X, how many targets it will have). She pays all costs, in this case by tapping her mana. Now Fireball is on the stack.
Alice receives priority, since she just put an effect on the stack. Pass.
Bob receives priority. Bob casts Snapcaster Mage. Same thing: put the card on the table, choose any parameters (none while casting it: you target his ability after he comes into play), pay the costs. Now Snapcaster is on the stack, above Alice's Fireball.
Bob receives priority, since he just put an effect on the stack. If Bob wanted to, he could play another (instant-speed) spell or ability at this time. He decides to pass.
Alice receives priority, since she is the other player and Bob passed. Alice passes. (Note that Bob does not get an opportunity to put anything new on the stack after Alice has passed, because he passed already as well.)
Now, since both players passed, they resolve the topmost thing on the stack, which is Bob's Snapcaster. The Snapcaster Mage spell resolves, becoming a Snapcaster Mage creature on the battlefield. His "enters the battlefield" trigger goes on the stack. Bob chooses a target for it: the Mana Leak in his graveyard. The stack looks like this: Snapcaster Mage trigger, Fireball.
Alice receives priority, because a spell just resolved. If she had Surgical Extraction, she could put it on the stack on top of the Snapcaster's trigger to remove Mana Leak before it has a chance to resolve. Alas, no dice. So she'll pass.
Bob receives priority. Pass.
Since both players passed, they resolve the topmost thing on the stack. Snapcaster Mage's ETB ability resolves. Bob's Mana Leak now has flashback 1U. The only thing on the stack is Fireball.
Alice receives priority, because a triggered effect just resolved. Pass.
Bob receives priority. If he passes now, the Fireball will go off. Instead, of course, Bob casts Mana Leak from his graveyard: Bob moves Mana Leak to the stack, targets Fireball, and pays its flashback cost by tapping mana. Now Mana Leak is on top of the stack, above Fireball.
Bob receives priority because he just played a spell. If he wanted to put another spell on the stack on top of Mana Leak, he could do so right now. Pass.
Alice receives priority. Pass.
Both players passed, so now Mana Leak resolves. During resolution, Alice gets the choice to pay 3 mana to stop it. She declines to do so. (If multiple players had to make choices -- like, for example, if you resolve Smallpox, you would go in APNAP order, just like you do after an effect resolves.) Then, Mana Leak counters the Fireball. Fireball is removed from the stack (going to Alice's graveyard). Since Mana Leak was cast with flashback, Bob puts the card into the exile zone. Now the stack is empty.
Alice receives priority because a spell just resolved. Since the stack is empty and it is her main phase, she can play any spell she wants, not just instants. Alice passes.
Bob receives priority. Pass.
Both players passed with an empty stack, so we go to the next step or phase (i.e. combat if this is Alice's first main phase).