As with all surgeries, spaying or neutering your rat is risky. Find an exotic vet that you trust who specializes in rats.
It is always a risk to put your rat under anesthesia, so ensure your rat is in good health and is of a proper age. 6 weeks to 6 months is preferred.

Spay

Females are spayed. Spaying includes the removal of the ovaries and/or the uterus.
Benefits: Reduced risk of mammary tumors, pituitary tumors, and uterine cancer.
A female rat will remain energetic even after a spay, although in some cases she may calm down. Spaying a female removes her ability to reproduce, and therefore her body will no longer go into heat every 4-5 days. During a female rat's heat, she may become increasingly energetic, excitable, and may shake and vibrate. This will no longer happen after a spay.
It's best to spay females between the ages of 3-6 months old, although younger and older rats will benefit from the surgery.
Pain medication should be given to your female for 3-4 days after surgery.
Neuter

Male rats are neutered. The surgery involves the removal of the testicles.
Benefits: Reduced production of testosterone which lessens the likelyhood that they'll become aggressive towards other rats. It is also unlikely that a sterile male will get harrassed by an intact male.
Since a neuter is less invasive than a spay, it is a good choice to get a male neutered if you are planning to introduce him to your female colony.
Rats become sterile after 8 days to 2 weeks. The only scientific study done discovered that all rats were infertile after 8 days. However, many people will urge you to wait longer to avoid unwanted pregnancies.
The neuter can be done at 4 weeks old, although 6 weeks to 6 months is ideal.
Pain medication should be given to your male rat for 3-4 days after surgery.
*If your male shows aggression towards you or other rats, find out if he's in pain or if it's hormonal. If it's hormonal, get him neutered asap.
Overall

It's up to you to weigh the benefits and the risks when deciding whether surgery is the best option for your pet!
If you plan to introduce your male and female rats, it's necessary to have one gender sterilized in order to avoid unwanted pregnancies that may result in
4 to 24 babies.
All rats should be given pain medication after their surgery for at least 3 to 4 days.
Some vets may tell you not to feed your rats prior to surgery, but this is unnecessary as rats cannot vomit. It's recommended to feed your rats and to provide their favorite treats for after the surgery.
You can place your rats back with their friends after the surgery. Make sure your rat doesn't remove the stitches. If they leave their stitches alone, they should recover in a few days time!
Always make sure that your rat is able to poop and pee after their surgery. They should also eat and drink like normal. It may take a few hours for the anesthesia to wear off. If they are unable to do any of these things, bring them back to the vet asap.