Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Top Tips for Agile Database Design

DZone's Guide to

Top Tips for Agile Database Design

Because change is bound to happen it is necessary to create a system that will allow this to occur as smoothly as possible.

· Database Zone
Free Resource

Finding a database that fits with a container-based deployment model can be frustrating. Learn what to look for in a Docker database

When creating an application or a database, it is crucial to take the way you approach agile database design into consideration from the outset in order to avoid issues down the road. Because change is bound to happen it is necessary to create a system that will allow this to occur as smoothly as possible. In order to have a scalable application, it is important to have a good database design. The data model and the database design define the structure of the database, the relationships between the data sets, and is part of the foundation on which the application is built.

It must be noted that database design is not the same as application source code. While both can act as blueprints for something that will be built and both can be changed over time, when source code of an application changes the entire application is rebuilt. The existing instances are not simply modified, but created anew. In contrast, database changes are applied directly to the instance. For this reason, application source code editing and maintenance methods will not work for a database design.

Likewise, while application source code only cares about the final state it ends up in, in database design, each individual change must be considered, and each change must be noted. Every change to the database needs to be recorded individually so that they can be applied to other instances of that database, and the final state of the database design itself should be recorded in the database model.

Furthermore, the only way changes should be made to an existing database instance is by changing the specific SQL statements. Changes cannot be partially implemented, meaning that it either is completed successfully or not at all and should be executed in the correct sequence for repeatability on behalf of any dependencies that exist between the changes.

It is a best practice that anyone who wants to make a change to the agile database design must first file a request and these should be recorded somewhere to provide an audit trail. Changes should then be reviewed and approved by the data modeler, to ensure a good, scalable design. The data modeler will also be responsible for updating the database model, which is the record of the database design, and producing the SQL statement that implements that change.

The above role can also get done through automation, causing the role of the database designer or data modeler to only be a full-time job during the first stage of development. While all development cycles will involve the database designer, the role itself could be filled by someone else within the development cycle, like a developer or database administrator, because it is no longer as time-consuming as it was during the outset.

Each database change should be given its own unique identifier, which identifies the particular change, regardless of the database instances it is applied to, or which versions of the application it appears in. Each change to a particular database instance must be recorded within the database instance itself in order to avoid applying the same changes twice. This implies that you maintain some form of change history table within each database instance, which should include the date and time each change occurred.

The set of changes should be stored in a single change log, which includes the change identifier and the SQL statement that implemented that change allowing for all necessary changes to be easily located and sequenced. This change log should be well structured so that a program can read and decode the changes in it, but there should be separate instances of the database design and the change log file in each version of the application source code so that changes can be made independently.

SQL statements are often specific to one database product, such as Oracle, Sybase, SQL Server or MySQL. The change log will need to record the separate SQL statements for each supported database product for each database change. Thus, each change that you make will have an identifier, and an SQL statement for database product that is clearly labeled with the database product name.

This whole solution is brought together in a program that is run during an application upgrade. It opens the change log XML file and reads in each change. If that change has not yet been applied to this particular database instance, then the corresponding SQL statement is executed and a record inserted into the Change History metadata table.

The importance of a well-made agile database design cannot be understated. While there are many best practices for developers, these are some specific tips that I have found to be useful. I believe that if you follow these tips you can ensure a scalable application that will run smoothly, despite the changes.

When you're looking for a SQL database that can scale elastically, while still preserving ACID guarantees, you only have a few choices. Find out how these elastic SQL databases perform in thishead-to-head YCSB benchmark.

Topics:
database ,data modeling ,sql ,agile

Published at DZone with permission of Yaniv Yehuda, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}