Storage water heaters fail by rusting through and leaking. That is almost always how they end.

Typical service life
Gas storage tank: 8 to 12 years.
Electric storage tank: 10 to 15 years.
Heat pump tank: similar to electric on the tank side, with the heat pump components having their own life.
Tankless: 15 to 20 years, and the components are serviceable rather than the appliance being disposable.
Water chemistry moves these substantially. Hard water and aggressive water both shorten tank life, and a maintained anode rod extends it markedly.
The signs
Rusty or discoloured hot water, particularly if only the hot side is affected. That is the tank's interior.
Water around the base. Any water from the body of the tank rather than from a fitting or the relief valve is a failed tank.
Rumbling or popping from a gas heater, which is steam forming under a sediment layer. Not itself fatal, and a sign the tank is overdue for a flush and is being run hot at the bottom.
Recovery has slowed noticeably, which on electric is often a failed element and on gas is often sediment.
Age past the warranty with no anode maintenance, which is the statistical answer rather than a symptom.
Where a failure is expensive
An attic or an upper floor, where a tank's contents come through a ceiling.
A finished basement.
Anywhere with no drain and no pan.
For those locations the calculation changes: replacing at twelve years rather than waiting for the leak is cheap insurance, and a pan with a leak sensor and an automatic shutoff valve is cheaper still.
Repair or replace
A failed element or thermostat on an electric heater is an inexpensive repair, worth doing at almost any age.
A failed gas control valve or thermocouple likewise.
A leaking fitting or relief valve is a repair.
A leaking tank is a replacement. There is no repair.
The judgement cases are a mid-cost repair on a heater past ten years, where the money buys an uncertain number of remaining years.
Replacing on your own schedule
A water heater that fails does so without warning and is replaced the same day, from whatever the plumber has on the truck.
A planned replacement allows a considered choice — a heat pump unit if the space suits it, the right size from a first hour rating calculation, incentives claimed, and a pan and shutoff fitted while the space is open.
For a heater past ten years in a location where a leak would do damage, that is the argument for acting early.
Extending it
Replace the anode when it is consumed, which is the single most effective thing available.
Flush annually to keep sediment off the burner or the elements.
Fit an expansion tank on a closed system, which stops the pressure cycling that stresses the tank.
Keep the temperature moderate, since scale and corrosion both accelerate with heat.
Fix high water pressure, which shortens the life of everything on the plumbing.
Those five together can push a tank well past its warranty, and each of them costs very little.
Warranties
Tanks are sold with warranties of six, nine or twelve years, and the difference between the tiers is usually a heavier anode and sometimes a thicker tank.
Buying the longer warranty is frequently good value, since the anode is exactly the component that determines life — and a household that will not maintain the anode is buying that maintenance up front.
Warranties cover the tank and generally require the heater to be installed to code, with an expansion tank where required, and registered. Each of those is routinely missed.
Keeping the paperwork
The model and serial number, the installation date, the anode replacement dates and the flush dates.
The serial number encodes the manufacturing date on most brands, which is how a plumber tells the age of a heater whose paperwork is long gone — and it is worth checking on a house being bought, because a fourteen-year-old tank is a cost arriving soon.
