The good news is that a microwave will give you plenty of signs to indicate it is time to replace it. A good microwave should last about 7 years under regular use. The magnetron (i.e., the part that makes the magic in a microwave) is designed to last about 2,000 hours.
If your microwave has been around a while and if you see the following symptoms, it is usually not worth getting a microwave repaired but to purchase a new one.
Examples of excessive wear and tear are as follows:
The door does not latch or seal.
The microwave starts making unusual noises.
The keypad is difficult to manage.
You notice sparking (please unplug immediately and get a new microwave).
Keypad sticks and needs force to operate.