Over a million developers have joined DZone.

The Two Types of Databases: Defines the World, or Reacts to the World

Does your database define and control its realm, or does it react to the actions of others? Read this checklist to find out and see which scenario works where.

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

There's a very simple distinction in the database world that tends to be ignored. Your database either defines the world or it reacts to the world.

If your database "defines the world," it means that if it doesn’t happen in the database, it doesn't happen at all. Amazon.com is a classic example of this — if you couldn't buy it on the web site then you haven't bought it. Payroll and accounting systems also fall into this category. Most early database applications were like this, and, as a result, APIs and developer mindsets still tend to assume that "defining the world" is the task at hand.

But increasingly, we are seeing systems that fall into the second category — those that react to an external reality that will keep on happening, with or without the database. It's the difference between playing at being an Air Traffic Controller while having the screen go dark and being a real controller and having the screen go dark, at which point the game has only just started if you are the controller.

Another example would be the phone system in the US — if the computer system that takes credit off your prepaid phone doesn't respond in under 100ms, the network will connect your call regardless of whether you have credit or not, because the telceoms don't want to antagonize you and prefer a situation where money is being lost at the rate of a few million dollars an hour.

This brings me nicely to my point — systems that react to the world usually struggle to escape from the consequences of either degraded service or a full outage. So while airplane pilots trust the controller, they also keep their landing lights on and use other gadgetry when near airfields and other airplanes — because research has shown that replacing one light bulb is consistently cheaper than replacing two airplanes.

"Reacts to the world" systems include pretty much all IoT and Connected Car applications, as well as any other situation in which you have devices "in the wild" that require some form of real-time back end processing to provide value to end users. But what does this all mean for developers? Does your database "define the world" or "react to the world?" Use our checklist below to determine which type of database you have — and which you need.

Data Modeling

Data Modeling is different in the "Reacts to the world" (R2W) scenario because you can no longer assume you will have full knowledge of all the data you are managing at any moment in time. You have to assume that the system will suddenly start, and be expected to act sensibly, when confronted by situations it may not fully understand.

Question: Does your data model cope with situations where you don't actually have full information?

Error Handling

Error handling is a big issue — normal development practice is to send utterly cryptic errors back to the application, which is akin to walking into a McDonalds, ordering a milkshake, and being told that a filter in the shake machine needs cleaning instead of, "We've got no shakes." Sending such an error message back makes sense if you can stop reality while the user asks for it to be fixed, but makes no sense in a world where reality continues with or without you.

Question: Will error handling allow you to provide a degraded service when things go wrong?

Latency Expectations

In a "defines the world" system, you might have an agreed SLA, but while an outage might have commercial consequences, it might be limited to forcing human customers to try again later. If you are interacting with other computers and you don't respond quickly enough, there may be far more significant consequences — imagine, for example, an air traffic controller whose screen is one minute behind reality.

For many IoT applications, millisecond latency is not just a matter of convenience — it can be the key to effective monetization. If you are trying to influence events while they are still happening, the lower your latency, the better things will be. For this reason R2W systems may need to be in-memory, as any kind of delay caused by disk access may serve to break your hold over events.

Question: Is your ability to function critically dependent on low latency?

Immediate Consistency

Returning to our air traffic controller example — imagine if one controller tried to hand off your airplane to another controller, but your airplane showed up at different physical locations on each of their screens? The database industry refers to this phenomenon of the same question receiving different answers for a while as eventual consistency. In a R2W scenario, eventual consistency is a major problem; if you are acting within milliseconds, you will presumably have made decisions that influence real-world events before the database finally settles on a single answer. Some of those decisions will be wrong.

Question: Does your application need immediate consistency?

Client Behavior When Ignored

Humans have an attention span of about seven seconds but will sometimes wait for minutes for a computer to respond. Humans also will get bored and find something else to do when confronted by a slow "defines the world" system. Machines, on the other hand, either stop functioning or re-send the same message when they don't get a response. If the back-end system has poor concurrency capabilities, you can get into a situation where the same machine has multiple requests trying to use the same resources to solve the same problem, and has thus deadlocked itself. Regardless of the architecture chosen, sooner or later there will be a network spike of some kind that will provoke this situation.

Question: Does your application need to cope with surges of activity and rapid, identical, cloned requests?

Asynchronous APIs

Surges and odd bursts of activity are a fact of life in the IoT and telecom spaces. These can either affect the IoT devices you are managing or other systems you are interacting with. Most legacy database platforms — and many newer ones! — have APIs which are synchronous: Once you start a call to the database, you are 100% dependent on the API returning control to your program quickly. This is obviously problematic, as your only way to cope with surges is to spawn more and more threads of activity. An asynchronous API allows you to carry a large number of simultaneous transactions without a correspondingly large number of threads.

Question: Does your application need an asynchronous API?


Most traditional "defines the world" systems have pre-announced periods of downtime. In the R2W space, the outside world can't be turned off, so concepts such as '5 9s' go from being nice to have to being commercially and practically important.

Question: Is downtime really, really expensive as opposed to merely being inconvenient?


A frequently-ignored aspect of the IoT is that we are now building R2W systems that will need to run for years and years, as they include hardware such as fridges and cars that consumers expect to last a long time. This in turn means that the architectural choices need to be equally long term. Open source stacks can be problematic here, as the frenetic pace of development means that either you suffer the expense of continually upgrading and changing running, tested code to use the latest technology, or you run the risk of finding yourself on an old, unfashionable and unsupported stack.

Question: Do you have a good plan for supporting your platform over a long period?


If you find yourself answering ‘Yes’ to most of these questions then you are probably in a R2W situation. Of the questions posed above, immediate consistency and latency are arguably the two most important. The question you now need to ask is whether your current plans are going  to allow you to succeed, or whether you need to step back and review your technology choices.

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.


Published at DZone with permission of David Rolfe, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}