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: 
The thing with science fiction settings is that when technology creates a problem for the PCs, it can also generally create a solution. Part of the heist genre is figuring out what the alarm systems are and getting your hands on the gadgets you need to neutralize them. Other valid tactics include social engineering tactics like bribing or impersonating the camera-watchers. The trick is getting players who realize that if they go up against alarm systems, they can lose very suddenly, and that therefore they need to do their homework and plan things out rather than rushing in blind.

Alternatively, if your PCs are working for an organization or higher power and don't have the means or wherewithall to deal with electronic security (no hacker or engineer-types), it's possible that "dealing with the alarm systems" is handled by someone or something else. If you go this route, you can also use it to build tension; "We can get you a four minute window of inactivity on the perimeter defenses. Don't waste it." Then you run into a complication on the way through and you're in jeopardy from the security systems, but it's not immediate / game-over jeopardy.
For a sci-fi setting, which was presupposed in the original question, make sure that one of the PCs is a Tech/Engineer/GreaseMonkeyType. She or He should be able with a very routine skill roll, to determine exactly what kind of surveillance system is being dealt with, and then with another skill roll of minor, moderate, or major difficulty, depending upon the sophistication of the systems in place, either to (1) disable the system entirely (the easiest solution), (2) fool the system into thinking no one is there so no alert is sent, but leave the system operating normally (this is a more difficult choice), or (3) send a false signal (this would be the most difficult of these three possible solutions). I'd allow the PCs to choose which method of disabling/subterfuge was being performed, and adjust the difficulty of the task accordingly.

This is equally do-able for a fantasy setting: If the alarm is a bell or gong that is located within sight of the PCs, a simple Silence spell will usually do the trick. If the room is being monitored via claivoyance/crystal ball/etc. then the PCs will require some advance notice of this monitoring. Judicious use of an Invisibility or other illusion spell, to either make themselves totally undetectable or else appear as creatures who belong in the area, should accomplish the goal. Teleporting past the room with the alarm would also work well, if that option is available to the PCs.