Question: When I design adventures, I often come up with situations where the NPCs could realistically thwart the PCs quickly by sounding an alarm. This is especially common in science fiction settings, where the NPCs have access to surveillance cameras, radars, motion detectors, and other advanced technology. This makes stealthy missions difficult to pull off, because the PCs can be revealed in a matter of seconds if they make even a single mistake.

**How do I keep NPCs from just sounding the alarm right way, without suspending disbelief too much?**

Answer: 
I think the single largest thing you can do to make sure that everything works smoothly is to make sure that everyone is on the same page as far as expectations. You are welcome to have any level of paranoia/security you want, as long as your players understand that going in. If they know it's there, they'll plan for it. If they're unaware for carefully crafted story reasons, it adds to the drama. If they just didn't know, that makes for a huge let down (most of the time).

I played in a sci-fi game where everyone on a planet wore Heart Monitors. One of the other players chose to be a killer robot. He wasn't aware that the moment he killed someone, he was causing an investigation. It escalated to a point where he should have just died to a police manhunt. All this was for smuggling a package that, if caught, would have resulted in a small reprimand. We had no idea of the setting, though. This happened in our first session. We never had a second session.

But, in the retelling, I want to illustrate that the expectations were what ruined that. The robot went in expecting to need to silence any observer. Turns out he made more of a mess by doing so. If he had known about the Heart Monitors, he would have changed tactics. And I think that is the extreme example of an alarm, but even that kind of immediate response could have been handled, with appropriate warning. Spoof the signal (even temporarily), or kill in such a way that the heart keeps going for a short bit, or something. Just make sure that the players know what's *possible* in the setting, let alone what they're facing at the current moment. If they know what's available, and the likelihood they might come across that tech, it's then their job to be prepared.
Usually in the games I'm a part of, the PCs' status as heroes sort of takes care of the alarm issue. If intruders easily slaughtered the 5 guys guarding your entrance, are you more likely to rush in there, or hunker down and take the best defensive position you can?

For more stealth or skill-oriented infiltrations, my approach is simply to allow multiple failures instead of one bad roll meaning a total failure. For example, a stealth failure could be described as, "A guard starts to turn a corner and his flashlight will shine directly on you. Everyone roll perception to see if they hear the guard in time to warn you." Chances are someone will make it, but then have some longer-term consequence. "You duck out of sight in time, but the guard thought he heard something suspicious and he's starting to check windows and doors for signs of forced entry."