1. Testing
Usually you never test something in a production environment and, in particular, on a production base basis for three reasons:
Performance: Testing can be CPU intensive and discard other precious resources of your servers. Since you do not want to reduce the productivity of the working environment during the tests, you should not use the production environment for this.
Data protection: you do not want to change data in your production database during tests. This means that not only your tests can have a limited range (i.e. you will probably think twice before testing some error, which can destroy all data related to your actual users, which allows the error to be used later by the hacker), but you can accidentally change the data by executing unverified code in your production database.
Security: if you are in the context of a company and have a team, you are likely to assign work related to tests to a dedicated tester. Giving this tester access to a production environment is not a good idea for security reasons.
1.1 Test environment
Test conditions should be as similar as possible to the production environment. For example, if you are testing an application that you send for Windows XP with the .NET Framework 3.5, you should not test it under Windows 7 with the .NET Framework 4, because everything will work during the tests and crash as soon as your clients start using Appendix.
Example: once I worked on an application using alternative NTFS data streams. Everything worked perfectly both during development and during tests, where no one thought that in 2009 FAT32 was still alive. Of course, once in production, a client installed the application on a FAT32 flash drive and crashed.
Please note that this does not mean that you must use the same environment during development.
In the case of databases, everything is different. The mechanism and version of the database should be the same, and the scheme should be the same (the same tables, the same restrictions, etc.) , but in most cases the data should be different , the test database is filled with some random data that is not related with the data that you have in production.
1.2 Database: Testing Bottlenecks
For example, if a website was recently released, you do not have a lot of data. If the database has a list of registered users, you will only have a few users at the beginning. On the other hand, you will probably need to test not only if your application is running , but also if the actions are correct and what are the bottlenecks . In this case, you will need to test it with large amounts of data: in this way, you can have several thousand users in the working environment and billions of randomly created user accounts in the test environment.
1.3 Database: validation of output
Another case where you want your test data to be different from production data is to avoid pasting HTML and to verify that the output is correct. If you have an e-commerce site, you have a SQL Products table, and each product has a title that will be displayed on the website. In a test environment, you should have products with names such as:
1. A very long name of a product goes here. Oh, this name is really huge! 2. javascript:alert('<a>&\é<%你好') 3. 4. '; delete * from Users
These names ensure that:
- Long names are displayed correctly,
- Names are escaped correctly, Unicode is supported and the encoding is correct,
- Empty names don't break the layout,
- SQL injection is excluded, but without exiting during output (in case the header can be changed via the website).
If you start populating the production database with such things, your users will probably think your site is broken or hacked.
2. Deployment
It all depends on the actual number of requests per second.
2.1 Small sites
If your site is small and not used too often, you really should not care about the update workflow. Copying modified source files may take less than a second because these files are small. If this really bothers you, you can schedule files to be copied during the day when there are few visitors. For most small websites, updating the source code in the middle of the night should be great .
In addition, there is nothing wrong with displaying a message that between 4 AM and 5 AM the server can go offline. Working sometimes at night, I often see these messages, for example, on my banking website, where, for security reasons, they may need to be disconnected once a week during maintenance or other scheduled tasks.
2.2 Server Farms
If your site is large and has thousands of requests per second, you probably have a server farm. In this case, the upgrade process should not be a problem, as the servers will be disconnected one by one, updated, and then returned to the farm .