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

Properly Getting Into Jail: This Ain't What You're Used To

DZone's Guide to

Properly Getting Into Jail: This Ain't What You're Used To

Let's see how you can incorporate the human element into your data systems, why that's important, and when it's useful to have.

· Database Zone ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

The inmate population in any typical prison is divided according to many and varying rules. It can be the length of the expected stay, it can be the level of security required, the kind of facilities required, the crimes committed, etc.

For simplicity, we’ll talk about Block A (minimum security, good behavior, low risk) and Block C (bitter lifers, bad apples, violent inmates, etc.) as our two examples. These differences can create very different environments: things that would never pass muster in Block A and could be routine in Block C and vice versa.

A good example would be the acceptance criteria: In order to be accepted to Block A, you have to meet certain standards (non-violent offenders or 8 years inside with no spots on your record, or a strong recommendation from an officer). In order to be sent to Block C, you need to be in a particular kind of trouble (violent crime, recent behavioral issues, high risk from intelligence, etc).

Being written up by a guard in Block A will result in loss of privileges, like not being sent to work, reduction in visitation, etc. You don’t get written up in Block C, you get sent to disciplinary action with the block’s officer and can be confined to the cell, isolation, lose cafeteria privileges, etc.

From the outside, both of these blocks are roughly the same, but from the inside, they have very different populations, behavior, and accepted practices.

This means that when we need to write a system that would serve both blocks (and there is also Block B, Isolation, and the Medical Ward as well, all slightly different), we are in somewhat of a pickle. How do we account for all of these differences?

One way to handle that would be to just deal with the common stuff (the counts, the legal dealing, etc.) and let each block dictate policy outside of the system. We can also provide some “note keeping” functionality, such as the ability to assign tasks, keep notes and records on inmates, and hope that the blocks would use that so we’ll at least have a record of all these policy decisions.

Alternatively, we can map what each block wants to do and customize the application for each of them. The problem here is that these things change, and when talking about a large enough basis, they change quite often.

Given a typical tenure of a block’s officer of about 3-5 years (really depends on the type of prison — in some cases, you’ll have tenures as short as a year or two) and the tendency of each new officer to want to make some changes (otherwise, why are they there?) and the fact that in a typical prison, you’ll have 3-6 blocks and about 10 high-level officers that each want to leave their mark (each with independent tenures), you end up with a fairly constant rate of low-level changes.

If this make you cringe at the expected number of changes that will be required to always adapt the system, I hear you. That isn’t a fun place to be in.

There are typically two major ways to handle this. Either you’ll ensure that no such changes are accepted, by not making the changes and having the prison work around the different practices while still using the system, or you plan to adapt things from the get-go. The first option is very common in a top-down organization, where the HQ wants to “lay down the law” about how things “should be done.” The other option is typically more expensive, sometimes ridiculously so, depending on how far you want to push it.

Dynamic data, forms, and behaviors, oh my! Let the prison guard completely re-design the system in his free time. To be fair, I was a prison guard and I would enjoy that, but I haven’t found many people in my current career that can say that they have prison experience (from either side of the bars). In practical terms, I would say that the technical level of prison guards is at or below the population norm and not at a level sufficient to actually do anything mission-critical, such as dealing with people’s freedom.

It is actually usually quite easy to convince the HQ people to avoid any flexibility in the system. They like ensuring that things are done “right,” even if that is quite different from how things are actually working (or even can possibly work). But we’ll avoid such power plays. Instead, let’s talk about how we can limit the scope of the work that is required and still gain enough flexibility for most things.

With RavenDB, defining dynamic data is both easy and obvious, so that is easy. Each block can define additional fields that they can tack onto documents and just have them there. The auto indexing features will also ensure that searches on such fields are fast and efficient. I’m not going to touch on any UI elements — that is someone else’s job.

Let us talk about policy decisions. For example, we might need to decide whatever an inmate is acceptable or not for a block. That means that we need to have some way to decide policy. Now, I have literally written a book about building DSLs for just such a scenario. You can very quickly build something simple and elegant that would give the user the chance to define their own policy and behavior.

In fact, given the target audience, this is not a good idea. We don’t expect the prison guard to make such decisions, so we don’t need to cater to them. Instead, we’ll cater to developers, probably the same developers who are in charge of actually building and maintaining the system. This gives us a very different flavor to deal with. For example, instead of building a DSL, we can just use a programming language.

For example, we can use JavaScript to shell out at critical parts of the pipeline. A good example would be at the validation stage of processing an incoming inmate. We’ll pass the inmate document to a JavaScript function, and that can emit validation warnings and actions that are supposed to take place. Here is a small sample:

function newInmate(inmate){
   if(inmate.status !== "final") {
      warn("This inmate's status isn't final. This block accepts only inmates with final judements.");
   }
   var violentCrimes = "23.93.1"; 
   if(inmate.warrants.filter(w => w.reelvantClause === violentCrimes).length == 0) {
      warn("This inmate doesn't have a history of violent crimes. Are you sure?!");
   }
}


The real world would probably have several pages of various business logic around what should and shouldn’t happen here — including things like assigning to a specific cell because of the inmate’s affiliation, etc. The idea here is that we’ll give the developers an easy way to go and modify the behavior of the system for each location this is deployed in.

As an aside, these kinds of things need to be logged and audited. That means that you can store these scripts in something like a git repository and record the commit hash for the version you are using when you are making decisions. In 99.9% of the cases, it will not matter, but if you’ll need to show to court why the “computer told us” that a certain inmate had to be dealt with in a certain way, you want to be able to know what happened and produce the right script that helped make that decision.

You might also note from the script that the output of the function is a set of warnings, not errors or exceptions. Why is that? Because there is an explicit place here for the human element. That means that if we have warnings for an inmate, we can still actually accept the inmate, despite the warnings. We might require the sergeant to note why the inmate is accepted despite the warnings (and answers may be things such as “they ran out of room in B” and “he was overheard saying he would stab someone”). This is because, quite explicitly, we don’t treat the system as the source of truth.

This system is the system of record: It holds the information about what is going on, but it isn’t meant to be rigid. It has to be flexible because we are dealing with people and there is no way that we can cover all situations. So we try to ensure that there is a place for the human element throughout the system design.

Do you pay to use your database? What if your database paid you? Learn more with RavenDB.

Topics:
database ,dynamic data ,dsl

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}