The web application database: why you need it and how it works
A web application database is where the service keeps everything users work with: accounts, orders, statuses, documents, action history. The browser shows the interface, the server runs the logic, and the database makes sure data is saved, stays consistent and can be found quickly. For a business, what matters is less the names of technologies than a well-designed data structure, backups with tested restores, careful migrations and responsible handling of personal data.
Open the software development page
Why a web application needs a database
An ordinary website can do without a database: its pages are the same for everyone. A web application is different. People work in it: they sign in to their own accounts, place orders, change statuses, upload documents. All of this has to be stored somewhere so that data is not lost when the server restarts, does not get mixed up between users and is still available a month or a year later.
A database solves several problems at once:
- It stores data reliably: a record is either saved in full or not at all, with no half an order.
- It keeps data consistent: an order cannot belong to a customer who does not exist, and an amount cannot turn out to be text.
- It lets many users work at the same time without overwriting each other's changes.
- It finds what you need quickly: a customer's orders, this week's requests, all unpaid invoices.
- It provides the basis for reports, integrations and backups.
How a web application differs from a website and what kinds there are is covered in our guide on what a web application is.
How it fits together: browser, server and database
A typical web application has three layers. The interface in the browser (the frontend) shows the screens and sends requests. The server side (the backend) checks permissions, runs the business logic and talks to the database. The database stores and returns records.
An important rule: the browser never talks to the database directly. All requests go through the server, which checks who is asking and what they are allowed to do. Calculations that affect money and permissions also run on the server, and the user is shown the result. This protects the database from forged requests and keeps the logic from being duplicated in several places.
Relational and document databases: an overview
There are many databases, but for most business tasks the choice comes down to two families.
| Relational (SQL) | Document | |
|---|---|---|
| How data is stored | Tables with rows and columns, links between tables | Documents with nested fields; structure can vary |
| Strengths | Consistency, relationships, complex queries and reports, transactions | Flexible structure, convenient for data of different shapes |
| Where they fit | Orders, payments, accounting, CRM, personal accounts | Catalogs with varied attributes, event logs, settings |
| What to keep in mind | The structure must be designed in advance and changed through migrations | Without discipline it is easy to end up with inconsistent fields and duplicates |
In practice a relational database is a common default for business applications: they have many linked entities (customer, order, payment, document) and accuracy matters. A document database or a separate store is added where data really is varied. The choice is made for the task, not for fashion, and explained in terms of the task rather than the stack.
What to keep in the database and what to keep next to it
Not everything an application works with belongs in one database. A typical split looks like this:
- In the database: records such as users, orders, statuses, amounts, the links between them and the history of changes.
- In file storage: the files themselves, such as scans, photos, PDFs and videos. The database keeps only a link and a description of the file.
- Outside the database and outside the code: secrets such as access keys for payment services and passwords for external systems. They live in protected server settings, not in the repository.
- In a cache: anything that can be recalculated, such as results of heavy queries or frequently requested reference lists.
- In a log: technical events such as errors, sign-ins and integration calls. The log is needed for investigating failures and should not get in the way of the main database.
Data structure: design it before the code
Mistakes in the data structure are the most expensive to fix later, because screens, reports and integrations rely on it. That is why the data structure, roles and access rights are designed early, together with user scenarios.
- Which entities the process has and how they relate: a customer has many orders, an order has many items and payments.
- What the master source of each record is: if prices are kept in the accounting system, the application receives them rather than edits them.
- Which fields are mandatory and in what format: phone numbers, dates, amounts, currencies.
- What must be kept in the history: who changed a status or an amount and when.
- How data of different clients is separated if this is a SaaS product with separate workspaces.
Migrations: changing the database without losses
An application evolves, and the database structure changes with it: a new field appears, a table is split in two, a format changes. Doing this by hand on a live server is risky. That is what migrations are for: step-by-step descriptions of changes that are stored with the code and applied the same way on every server.
- Each migration is small and clear: one change, one step.
- Before it is applied on the production server, it is tested on a copy of the data.
- Changes that delete or rewrite data are made as a separate, deliberate step and only after a backup.
- A new version of the application is released so that it works both before and after the migration, so deployment does not stop the service.
Backups
A backup is needed not just in case but for specific events: a faulty update, accidental deletion, a server failure. A good scheme answers three questions.
- How often a copy is made and how much data can be lost between copies.
- Where the copy is kept: not on the same server as the database.
- Whether restoring has been tested: a backup nobody has ever restored from is a hope, not protection.
Backups and failure alerts are part of what the client receives with a finished web service, and checking them regularly is part of maintenance. How it works is described on the software support and development page.
Personal data
Almost every business application stores personal data: names, phone numbers, addresses, order history. It comes with special requirements, both from the laws of the country you operate in and from common sense.
- Collect only what the process really needs.
- Separate access: an employee sees only the data their role requires.
- Protect data in transit with encryption and restrict access to the database server itself.
- Log who viewed and changed sensitive data and when.
- Decide in advance where user data is physically stored: in some countries this is regulated by law.
- Provide for deleting data at the user's request and when the retention period ends.
The requirements of a specific jurisdiction are worth checking with a lawyer before design, not after launch.
Performance: why an application starts to slow down
At the start there is little data and everything is fast. A year later there are hundreds of times more records, and screens that used to open instantly start to lag. The cause is usually in the database, and it can be found.
- There are no indexes on the fields used for searching and sorting, so the database scans every record.
- A screen makes dozens of small queries instead of one well-designed query.
- Lists are loaded in full instead of page by page.
- Heavy reports run on the same database at peak hours and get in the users' way.
- Files are stored directly in the database and bloat it.
The fixes are targeted: measure slow queries, add indexes, paginate results, move reports and heavy tasks to background processing. Rewriting the whole application is usually not necessary.
Moving data from spreadsheets and old systems
A new application rarely starts with an empty database: customers, orders and reference data already live in spreadsheets or an old system. The transfer is planned as a separate task: fields are mapped to the new structure, duplicates and inconsistent formats are cleaned up, and a trial load and reconciliation are carried out. More on such transfers is in our guide on CRM development for your process, and on linking the new database to other systems, see the business process automation page.
How we approach data in web applications
We plan the data structure, access rights and multiple languages at the design stage, not right before launch. Money is calculated on the server, secrets are kept outside the code and the repository, and together with the service the client receives configured backups and failure alerts. We choose the database technology for the task and explain the choice. More on the web app development page, and you can describe your task on the software development page. How an application comes together as a whole is covered in our guide on business app development.
Frequently asked questions
Why does a web application need a database?
To store accounts, orders, statuses and history reliably, avoid losing data in failures, let many users work at the same time and find the right records quickly.
Which database to choose: relational or document?
For business applications with linked data such as orders, payments and customers, a relational database is the more common choice. A document database suits varied data. The choice is made for the task.
Can files be stored in the database?
Technically yes, but files usually go into separate file storage while the database keeps a link and a description. That keeps the database compact and fast.
What is a database migration?
A step-by-step description of a change to the database structure, stored with the code and applied the same way on every server. Migrations are tested on a copy of the data before they are applied.
How often should backups be made?
It depends on how much data you can lose without harm. What matters is keeping copies separate from the main server and regularly testing restores.
Why has the web application become slow?
Most often because data has grown: missing indexes, lists loaded in full, reports built at peak hours. It is fixed with targeted changes, without rewriting the application.
How do you protect personal data in the database?
Collect only what is needed, separate access by role, encrypt data in transit, keep an access log and decide in advance where the data is physically stored.