Code can fail for many reasons. Maybe a dependency isn’t responding, or something else has a lock on a resource you want. Your customers may have found an unexpected way to use your application or hit corner cases you didn’t anticipate. If we adopt a mindset that our code will fail, we can move to adopt strategies that handle failures well. In this chapter, we’ll look at common .NET tools and techniques that isolate problems, retry, and compensate.
Sometimes, it seems that the things we build today don’t last long. Even though it’s only 20 years old, my driveway is slowly crumbling, and the concrete needs to be removed and replaced. Yet the Roman Pantheon, built almost two millennia ago, is still standing strong. Researchers recently discovered that the reason why this concrete lasts so long is that it has properties that allow it to heal. Whether by accident or intention, Roman concrete was designed to handle failure. My driveway, by contrast, was designed to be inexpensive.