Water heaters have been designed to prevent this by using a sacrificial anode rod. The anode rods work by giving up their electrons more quickly than the steel tank. Called “active metal,” that is usually magnesium.
SRBs eat the sulfate (SO4), a mineral found naturally in groundwater, and transform it into H2S. They’re ancient creatures that have been around since Earth’s atmosphere was devoid of oxygen.
If smells are also present in the cold water side of your system, the issue could be with the water source, treatment system, or your plumbing. It is good to have the water you drink tested frequently(EPA) to identify a range of contaminants, mainly when you depend on an underground well or another private water source.
A powered anode rod is one of the best solutions to get rid of the hot water heater egg smell. These come with a tiny titanium anode that is non-sacrificial and attaches to the water heater to replace the sacrificial anode rod.