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: 
In general my PCs know that any sneaking into fortress, castle, hi-rise, brothel is not going to be a cakewalk. I encourage them to approach it in a realistic manner such as scouting, social engineering, getting low level jobs to scout the inside, use of hidden mikes, tracking devices and robots.

Also for the most part I allow a little leeway such as if the PCs are sneaking in and forget to announce they are on the lookout for guards, detection devices and such. I assume they are since they are sneaking in.

If they are pretty much taking no pre-cautions feel free to bring the full effects of their actions to their attention. They may escape and find themselves having to break into the same place that now has triple the guards and double the detection devices.

Example

The party had to break into a mansion to steal a prototype sniper rifle. The mansion was well guarded with troops, automated turrets, cameras, dogs, motion detectors, x-rays. Part of the party staked it out while the rest tried to find weakness in the defenses. After a few days they discovered a weak link. Any food going in was not X-Ray'ed that with the fact they knew the owner of the mansion was having a birthday soon. So they split up some got in via the birthday cake, another got in by kidnapping and replacing one of the drummers for the band playing, the rest got in as wait staff (they found out wait staff badges where low level but the easiest to reproduce).
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."