The short answer is that you cannot totally avoid having the site down while doing database updates.
The key though, is to have a process in place that minimizes the downtime.
The steps below are taken directly from Jisse Reitsma @ Yireo, you can read the full article here
1. Shadow environment
The first step would be to create a copy of the production environment, preferably in the same root folder as the production site. Next, you can update that copy, which might take minutes. Once you are done, you replace all of the files of the production site with the new files of the shadow environment and finalize the deployment to production.
To run the changes on the files, the following steps are needed:
Again, this might take minutes. It might even go wrong. However, if all of this takes place in a shadow environment, there is no risk to the production site. Only once all of the steps are completed succesfully, you can move to the second stage - putting these file updates actually in production.
2. Switching between shadow and production
Switching shadow and production could be done through simple folder operations
(mv b c; mv a b; mv b a;) or symlinking. Actually, the procedure of working with symlinks is part of the approach of Capistrano, so if you are looking for a better tool to deploy Magento 2, opt for Capistrano.
3. Finalizing production
So now you can swap all of the files of the actual production site with the files that you gathered in the shadow environment. The only thing that remains is to run the database changes, which is done in Maintenance Mode.
bin/magento setup:upgrade --keep-generated
The previous code-gathering step might have taken minutes to complete. This database step usually takes 1 or 2 seconds. Meaning: With this procedure you never have more than a few seconds downtime, unless you mess up.
The important part here is when you run
bin/magento setup:upgrade --keep-generated.
Because, by default the
upgrade command will wipe out all of the generated DI files and the copied view-files. To prevent this from happening (because you already generated these files in the steps above), you add the flag