How to Ensure Your Website is Stable
Stability means more than just keeping your website up and running. It also means removing anything that could make it more prone to failure in the future.
If there's a certain combination of actions that will cause the site to crash and the client should never do them, they shouldn't even be able to do them. Just eliminate the possibility. If they have to do step 1 before step 2 or things will blow up, why are they even allowed to do step 2 first? They should only be able to do things that are safe.
Stability also means ensuring there are no time bombs in your code that could cause problems down the line. For instance, maybe importing 100 products is fine, but importing 1,000 products will cause the site to freeze up and crash. That might be fine for now, because you only have 100 products. But are you never going to have more? You shouldn’t have these traps where the code works right now, but a change in circumstances will cause it to suddenly not work.
So what can you do?
Remove harmful options. Check if the parameters are met. If they aren't, and this option will cause things to blow up, don't show this option. If step 1 has to come first, make sure step 2 is not available.
Warn the user where appropriate. Some functions are valid, but are so powerful that you need to warn people with a message—i.e. "You're changing all the products; are you sure to want to continue?"
Present error messages to help the user. If importing more than 100 products will cause the site to crash, throw up a warning that says, "You cannot import more than 100 products, please decrease you import size." Don't let the site just die with no explanation.
Enforce what needs to be enforced. Say you build a function that only works if the product has a UPC code attached to it. Don't just assume the user will enter a UPC; make it a requirement, and throw an exception if it isn't there.
Be careful with hard coding. Say you connect to an API, but the API address is built right into the code—and then in a year they change it. Now you have to update the whole module. If you had just made that a setting, it could be changed much more easily.
The best way to see if a site is stable is to test failure cases. If it's supposed to get a value between 1 and 10, put in 100, or the letter "J," or anything else that is an invalid answer. What happens? Does it explode? Does it work fine?
Look for the common fail points and deliberately try to create those failures so they can't exist in the future. But try to be somewhat generic. Maybe you define four successes, so anything that's not those should generate some sort of generic error message.
TLDR: Make your website stable. Don't build your code with time bombs in it.
More from Acro Media
- High Five: Technical Debt: Why it's Bad and How To Avoid It
- High Five: Automated Drupal Code Testing: What, Why, and When To Do It
- Video: How Memory Works in PHP and Its Hidden Costs
- Drupal Commerce 2: Technical Overview
- Learn more about Acro Media
Chat with us
Do you need help with your Drupal Commerce website, are you looking to rebuild or replatform to Drupal Commerce, or maybe you just want to learn more about Drupal Commerce, we're happy to help you out. Talk to us today.