Water on a shingle field runs straight down. Water at a junction has to be given somewhere specific to go.
Drip edge
The metal strip along the eaves and rakes does two jobs. It holds the shingle edge proud of the fascia so water drips clear into the gutter rather than running back underneath, and it protects the exposed edge of the decking from wicking moisture. Underlayment and drip edge have a specific relationship depending on whether they are at the eave or the rake, and getting it wrong sends water behind the metal instead of over it.
Step flashing at walls
Where a roof slope meets a vertical wall, water running down the wall has to be turned away from the junction. Step flashing does this with a series of small L-shaped metal pieces, each one layered under a shingle and over the one below it, so that every course sheds onto the next. Counterflashing is then cut into the wall and folded down over the step flashing. When this is done with one long continuous piece instead of stepped sections, it works until the building moves, and then it fails.
Valleys
A valley concentrates the runoff of two slopes into a single channel, so it carries far more water than any other part of the roof. Valleys are lined with metal or a purpose-built valley material, shingles are cut and sealed along the valley line, and the channel is kept clear of debris. A valley blocked by leaves holds water against shingle edges, which is exactly where it should not be.
Penetrations
Plumbing vents, exhaust outlets, skylight kerbs and antenna mounts are holes punched through a waterproof surface. Each one relies on a boot or a kerb flashing that seals the opening and sheds water over the surrounding shingles. Rubber boots age and split with ultraviolet exposure; this is one of the most common small leaks on residential roofs and one of the easiest to fix.
Ridge and hip
Ridge cap covers the top of the roof where two slopes meet, and has to shed water onto both sides while resisting the highest wind loads on the building. Where a ridge vent is installed, the cap sits over a continuous slot. Nails through the cap are placed deliberately so they are covered by the next piece; a ridge cap nailed in the wrong place is a line of leaks along the highest point of the house.
Next step
Have this looked at on your own roof?
Robert Ryberg answers the phone and texts himself. An assessment on your property turns any of this from general guidance into a specific answer.