﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>https://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Properly getting into jail: The almighty document</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-almighty-_C1CA/image_2.png"&gt;&lt;img width="219" height="274" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-almighty-_C1CA/image_thumb.png" border="0"&gt;&lt;/a&gt;This post is the conclusion for this series (unless I’ll get some interesting questions). So far, I outlined how to break apart the system, the data flow and data processing inside it, a lot about the internal constraints and the business logic as it is applied. There hasn’t been a lot of code, because I wanted to keep things at the architecture level rather do low level dive. &lt;/p&gt;&lt;p&gt;Early in the series, I got a &lt;a href="https://ayende.com/blog/182114-C/properly-getting-into-jail-services-with-data-sharing-instead-of-rpc-or-messaging?key=30377850960e4a8183a6b5309e5e41ce#comment1"&gt;comment&lt;/a&gt; from Rafal that is pretty profound:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;There's a general agreement among software creators and their customers that software replaces papers and going paperless is A Good Thing ™. And then after introducing an IT solution everyone starts complaining that the papers were so much better to work with and allowed for much greater flexibility. Especially for order handling workflow, where you could print copies of the order, hand it out to proper people and be sure they have everything they need to do the job. And you could always put some additional info on the papers when there was a need for special handling. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The rigidity of computer systems often means that we have to work around the system in the real world to get things done. In many cases, that actively &lt;em&gt;hurt&lt;/em&gt; the people using the system. For example, if I got an inmate that had a specific constraint (danger to himself, isolated from a particular group, etc), I can take a red marker and write in big letters on the file the message, ensuring that everyone that deals with the file is aware of it. If this is not explicitly called out in the design of the system, there is really no good way to do that with a computer system. And that can be a great deterrent for adopting the system and its usage.&lt;/p&gt;&lt;p&gt;What is worse, if you have such a requirement, it will often show up as something like this:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-almighty-_C1CA/image_4.png"&gt;&lt;img width="438" height="460" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-almighty-_C1CA/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;A mandatory, annoying (and never read) message box that isn’t actually useful for the purpose. &lt;/p&gt;&lt;p&gt;One of the rules that we have as system architects is explicitly anticipating and answering this kind of situations and providing something that can do at least as good as plain old paper. &lt;/p&gt;&lt;p&gt;The design on Macto as outlined in this series of posts attempted to do just that. To continue Rafal’s quote:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;And your approach is the same idea applied to software design - make a digital piece of paper that almost physically follows the process, is always there and has everything necessary to do the work, then pass it around and just make sure it's not lost somewhere in between. No central registry, no central decision about where the papers go, just do your task and pass the message to the next station.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Doing something in the UI like getting the user the ability to inject some elements is trivial, after all, if the data format can handle it. So you have a way to record the information the user want and display it in a way that make sense to them, without having to know more about UI design than Right Click &amp;gt; Add (Field / Note / Heading / Timer), etc. At the same time, you gain all the benefits of a computerized system (backups, search, recall, etc), the ability to avoid signing things in triplicate, have access to the entire status of the system at once, etc.&lt;/p&gt;&lt;p&gt;This is not a trivial thing to do, but it can result in quite a different to the system and its adoption.&lt;/p&gt;</description><link>https://ayende.com/blog/182209-C/properly-getting-into-jail-the-almighty-document?Key=47f4f393-ca67-4373-b4ad-479ab60aa8c4</link><guid>https://ayende.com/blog/182209-C/properly-getting-into-jail-the-almighty-document?Key=47f4f393-ca67-4373-b4ad-479ab60aa8c4</guid><pubDate>Mon, 19 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Data processing</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/image_2.png"&gt;&lt;img width="773" height="352" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/image_thumb.png" border="0"&gt;&lt;/a&gt;In this series of blog posts, I have talked a lot about the way data flows, the notion of always talking to a local server and the difference between each location’s own data and the shared data that comes from the other parts of the system.&lt;/p&gt;&lt;p&gt;Here is how it looks like when modeling things:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/Snapshot_4.png"&gt;&lt;img width="379" height="209" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/Snapshot_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;To simplify things, we have the notion of the shared database (which is how I typically get data from the rest of the system) and my database. Data gets into the shared database using replication, which is using a gossip protocol, is resilient to network errors and can route around them, etc. The application will only ever write data to its own database, never directly to the shared one. ETL Processes will write the data from the application database to the local copy of the shared database, and from there it will be sent across to the other parties.&lt;/p&gt;&lt;p&gt;In terms of input/output, the process of writing locally to app DB, ETL process to local shared DB, automatic dissemination of data to the rest of the world is quite simple, once you have finished the setup. It means that you don’t really have to think about the way you publish information, but can still do that in such a way that you are not constrained in the development of the application (no shared database blues here, thank you!).&amp;nbsp; However, that only deals with the outgoing side of things, how are we going to handle &lt;em&gt;incoming&lt;/em&gt; data? &lt;/p&gt;&lt;p&gt;We need to remember that a core part of the design is that we aren’t just blindly copying data from the shared database. Even though this is trusted, we still need to process the data and reconcile it with what we have in our own database. &lt;/p&gt;&lt;p&gt;A good example of that might be &lt;a href="https://ayende.com/blog/182115-C/properly-getting-into-jail-the-workflow-of-getting-an-inmate-released"&gt;the release inmate workflow&lt;/a&gt; that we already discussed. This is initiated by the Registration Office, and it is sent to all the parties in the prison. Let’s see how a particular block is going to handle the processing of such a core scenario. &lt;/p&gt;&lt;p&gt;The actual workflow for releasing an inmate needs to be handled by many parties. From the block’s perspective, this means getting the inmate physically into the release party and handing over responsibility for that inmate. When the workflow document for the inmate release reaches the block’s shared database, we need to start the internal process inside the block to handle that. We can use RavenDB Subscriptions for this purpose. A subscription is a persistent query, and any time a match is found on the subscription query, we’ll get the matching documents and can operate on that. &lt;/p&gt;&lt;p&gt;Here is what the subscription looks like:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/image_4.png"&gt;&lt;img width="493" height="303" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-processi_986C/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Basically, it says “gimme all the release workflows for block B”. The idea of a persistent query is that whenever a new document arrives, if it matches the query, we’ll send it to the process that has this subscription opened. This means that we have a typical latency of a few milliseconds before we process the document in the worker process.&lt;/p&gt;&lt;p&gt;Now, let’s consider what we’ll need to do whenever we get a new release workflow. This can look like this:&lt;/p&gt;&lt;blockquote&gt;&lt;script src="https://gist.github.com/ayende/ab72456c2794656e7db2395a51239a0a.js"&gt;&lt;/script&gt;&lt;/blockquote&gt;&lt;p&gt;I’m obviously skipping stuff here, but you should get the gist (pun intended) of what is going on.&lt;/p&gt;&lt;p&gt;There are a couple of interesting things in here. First, you can see that I’m writing the code here in Python. I could have also used Ruby, node.js, etc.&lt;/p&gt;&lt;p&gt;The idea is that this is an internal ingestion pipeline for a particular workflow. Independent of any other thing that happens in the system. Basically, the idea is to have a Open To Extension, Close To Modification kind of system.&amp;nbsp; Integration with the outside world is done through subscriptions that filter the data that we care about and integration scripts that operate over the stream of data. I’m using a Python script in this manner because it is easy to show how fluid this can be. I could have use a compiled application using C# or Java just as easily. But the idea in this architecture is that it is possible and easy to modify and manage things on the fly.&lt;/p&gt;&lt;p&gt;The subscription workers ingesting the documents from the subscriptions take the data from the shared database, process and validate it and then make the decisions on what should be done further. On any batch of workflow documents for releasing inmates, we’ll alert the sergeant (either way, we need to release the inmate or we need to figure out why the warrant is on us while the inmate is not in our hands). &lt;/p&gt;&lt;p&gt;More complex script may check all the release workflows, in case the block that the Registration Office thinks the inmate is on is out of date, for example. We can also use these scripts to glue in additional players (preparing the release party to take the inmate, scheduling this in advanced, etc), but we might want to do that in our main app instead of in the scripts, to make it more visible what is going on.&lt;/p&gt;&lt;p&gt;The underlying architecture and shape of the application is quite explicit on the notion of data transfer, though, so it might be a good idea to do it in the scripts. A lot of that depends on whatever this is shared functionality, something that is customized per block, etc.&lt;/p&gt;</description><link>https://ayende.com/blog/182177-C/properly-getting-into-jail-data-processing?Key=52fc3012-db68-4cac-979f-93bbeaf67bf3</link><guid>https://ayende.com/blog/182177-C/properly-getting-into-jail-data-processing?Key=52fc3012-db68-4cac-979f-93bbeaf67bf3</guid><pubDate>Fri, 16 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: My service name in Janet</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-My-service-na_9A42/image_7.png"&gt;&lt;img width="672" height="285" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-My-service-na_9A42/image_thumb_2.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;For a long time, whenever I was talking to customers about the business domain, I would explicitly avoid using the term “business logic”. Primarily because I never found such things to be logical in any way shape or form. A lot of the business decisions and policies are driven by a host of legacy reasons, “this is how everyone does it” and behaviors that has became accepted and then entrenched.&lt;/p&gt;&lt;p&gt;Take what is supposed to be a pretty simple rule. Given a warrant, when should an inmate be released? On the face of it, that seems like a pretty obvious and straightforward answer, right?&lt;/p&gt;&lt;p&gt;Depending on the type of warrant (can be for 48 hours, 5 days, 30 months, 10 years, life) the answer is quite different. For example, if someone was arrested at 3 PM on Thursday on a 48 hours hold, he &lt;em&gt;must &lt;/em&gt;be released on Saturday at 3 PM. But that is actually a problem, because the prison does not release inmates on Saturday. So the release date is moved back (or forward(!), depending on a lot of stuff). &lt;/p&gt;&lt;p&gt;If an inmate is sentenced for life, that might mean that he is expected to die in prison, be released in 10 years, 25 years or be eligible to go on parole in 14 years and be effectively free. I did some research around sentencing rules around the world and I must say that this is confusing and quite sad. Even within a single legal system the amount of complexity, precedent, custom and variance is staggering. &lt;/p&gt;&lt;p&gt;At any rate, we need to figure out something that seems to be quite simple. Given an inmate and the warrants we have on file, what should be the release date. This can be as simple as having a single warrant, or a series of sequential warrants (arrest, held until trial, sentencing, etc). That is simple and pretty obvious. Go to the latest warrant, get the duration from that and then start computing the release date. Here we have another problem, from what date do we start counting? If the inmate has been under arrest for the entire duration, then we start from that point. If the inmate has been free (bail, etc), then we start from the point he got put back into prison. Sometimes the inmate was held for a while (several months, before getting bail, for example), so that will be counted against the sentencing period (or not, depending on a bunch of stuff). In short, being told “you are hereby sentenced to 10 years” can mean several different release dates, even assuming nothing changes. &lt;/p&gt;&lt;p&gt;So this is complex, and hard, and in many cases very much situational dependent. How do you approach handling this?&lt;/p&gt;&lt;p&gt;To start with, this is one of those cases that you can, should and require to get a specification, complete with examples, test suite and samples, etc. It may sound silly, because all we are doing is computing a date, but the implications are… important, especially for the people who are being held. &lt;/p&gt;&lt;p&gt;The specification will have a few straightforward cases, but also a lot of convoluted mess that with luck, you can get a lawyer to decipher, but most likely not. The way to handle that is to recognize the patterns that you know that you can reliably figure out and provide answers to those. If it was up to me, I’ll be producing a long hand report, like so:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-My-service-na_9A42/Snapshot_4.png"&gt;&lt;img width="438" height="460" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-My-service-na_9A42/Snapshot_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Note that this computation sheet is not the final say, instead, the Registration Office officer is going to sign on that, after having validated the dates independently.&lt;/p&gt;&lt;p&gt;For patterns that aren’t so easy to compute, a good way to handle that is to show the information you have and &lt;em&gt;not&lt;/em&gt; give any answer, making the officer that will sign up on the correctness of this result do all the work.&lt;/p&gt;&lt;p&gt;As an aside, printing this report, including the computation and how it was arrived is a really good idea because it can be handed to the inmate as well as to their attorney. At this point, presumably they’ll double check the dates as well. This is important since a mistake in releasing an inmate that didn’t happen yet is free. After all, if an inmate is supposed to walk out on 2022 but we computed the sentence until 2025 and it was discovered in 2018, no harm was done (except maybe to someone’s nerves). &lt;/p&gt;&lt;p&gt;The human in the loop model is quite important in this regard, because of the notion of the single responsibility that I previously mentioned. Someone, a person, in actually responsible for the release date computation, and that should probably be a human that isn’t the system developer from a decade ago.&lt;/p&gt;</description><link>https://ayende.com/blog/182118-C/properly-getting-into-jail-my-service-name-in-janet?Key=33285882-8666-49c8-b4f0-2f87bf8a6878</link><guid>https://ayende.com/blog/182118-C/properly-getting-into-jail-my-service-name-in-janet?Key=33285882-8666-49c8-b4f0-2f87bf8a6878</guid><pubDate>Thu, 15 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: This ain’t what you’re used to</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-This-aint-you_9C0F/image_2.png"&gt;&lt;img width="385" height="204" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-This-aint-you_9C0F/image_thumb.png" border="0"&gt;&lt;/a&gt;The inmate population in any typical prison is divided according to many and varying rules. It can be the length of expected stay, it can be the level of security required, the kind of facilities required, the crimes committed, etc. &lt;/p&gt;&lt;p&gt;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&amp;nbsp; very different environments. Things that would never pass muster in block A and routine in block C and vice versa.&lt;/p&gt;&lt;p&gt;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 records or 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).&lt;/p&gt;&lt;p&gt;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. &lt;/p&gt;&lt;p&gt;From the outside, both of these blocks are roughly the same, but from the inside, they have very different populations, behavior and accepted practices. &lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;Alternatively, we can map what each block wants to do and customize the application for each of them. The problem here is that this 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 depend 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&amp;nbsp; 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.&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;&lt;p&gt;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. &lt;/p&gt;&lt;p&gt;Dynamic data, forms and behaviors, oh my! Let the prison guard completely re-design the system in his free time. To be fair, &lt;em&gt;I &lt;/em&gt;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 &lt;em&gt;not&lt;/em&gt; at a level sufficient to actually do anything mission critical such as dealing with people’s freedom. &lt;/p&gt;&lt;p&gt;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 &lt;em&gt;can&lt;/em&gt; 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.&lt;/p&gt;&lt;p&gt;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 &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-This-aint-you_9C0F/wlEmoticon-smile_2.png"&gt;.&lt;/p&gt;&lt;p&gt;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 &lt;a href="https://www.amazon.com/DSLs-Boo-Domain-Specific-Languages/dp/1933988606"&gt;written a book about building DSLs&lt;/a&gt; for just such a scenario. You can very quickly build something simple an elegant that would give the user the chance to define their own policy and behavior.&lt;/p&gt;&lt;p&gt;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 give us a very different flavor to deal with. For example, instead of building a DSL, we can just use a programming language.&lt;/p&gt;&lt;p&gt;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:&lt;/p&gt;&lt;blockquote&gt;&lt;script src="https://gist.github.com/ayende/100d033427949b5fa1a066db80b0f6f1.js"&gt;&lt;/script&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;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 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.&lt;/p&gt;&lt;p&gt;As an aside, this kind of things needs 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 help made that decision. &lt;/p&gt;&lt;p&gt;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 run 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.&lt;/p&gt;&lt;p&gt;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.&lt;/p&gt;</description><link>https://ayende.com/blog/182117-C/properly-getting-into-jail-this-aint-what-youre-used-to?Key=6368ffb2-f721-4fcb-9206-f9599e55b9a1</link><guid>https://ayende.com/blog/182117-C/properly-getting-into-jail-this-aint-what-youre-used-to?Key=6368ffb2-f721-4fcb-9206-f9599e55b9a1</guid><pubDate>Wed, 14 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Didn’t we already see this warrant?</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Didnt-we-alre_79AB/image_2.png"&gt;&lt;img width="341" height="232" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Didnt-we-alre_79AB/image_thumb.png" border="0"&gt;&lt;/a&gt;An interesting problem in distributed work shows up quite frequently in the prison space. Duplicated, delayed and repeated warrants (um… I mean packets). This can lead to some issues, especially since the receiving parties may or may not be in communication with one another.&lt;/p&gt;&lt;p&gt;Consider the case of a warrant to release a particular inmate. It is quite common for the process of actually getting the warrant back to the prison from the court to take a few hours. In that time frame, the inmate’s lawyer has already arrived at the gates of the prison and handed the release warrant to the block’s sergeant (it’s a bit more complex than that, but I’m skipping details here because I want to talk about the technical details of building a system to run a prison rather than the actual details of running a prison).&lt;/p&gt;&lt;p&gt;At this point, the block’s sergeant can pass the warrant off to the Registration Office, which will also accept the warrant from the court at some time in the future or they can initiate the release process directly. What actually happens depends on a lot of factors, but let’s say that they start the release process directly. We already talked about &lt;a href="https://ayende.com/blog/182115-C/properly-getting-into-jail-the-workflow-of-getting-an-inmate-released?key=83b0cbc75b894d69a69a5719c1ac5761"&gt;what that would mean&lt;/a&gt;, so let’s focus on another aspect of that. How do we deal with the arrival of the warrant to the Registration Office when there is already an open workflow to release the inmate.&lt;/p&gt;&lt;p&gt;For fun, here is an brief example of a warrant:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Didnt-we-alre_79AB/image_4.png"&gt;&lt;img width="908" height="211" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Didnt-we-alre_79AB/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Yes, this is faxed, often unreadable and sometimes coffee stained. There is no such thing as a warrant id that you can use to check if the warrant has already been seen. There is &lt;em&gt;supposed&lt;/em&gt; to be, at least per court / judge, but there often just isn’t. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Side note regarding the issue of faxing warrants. Yes, there have been cases where people &lt;a href="https://www.theguardian.com/world/2013/oct/17/florida-convicted-murderers-released-forged-documents"&gt;just sent a release warrant&lt;/a&gt; and people got out. Part of the process of actually processing a release warrant is talking with the court to validate it, but that isn’t always done.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Another fun fact is that what one warrant may do another warrant may undo. So you may have a release warrant on hand, but the court has already issued a stay of 48 hours for that warrant so the police can appeal that, for example. If the second warrant doesn’t arrive in time…&lt;/p&gt;&lt;p&gt;At any rate, the fact that a warrant may show up multiple times and that there may be conflicting warrants being processed at the same time means that there is the need to handle some level of de-duplication. We can usually detect that using the inmate’s details and the date in which the warrant was issued (it is rare that multiple warrants for the same person are issued at the same date, so that is enough to flag things).&amp;nbsp; If the result of two warrants on the same date is the same, we can assume that they are the same. &lt;/p&gt;&lt;p&gt;If there are conflicts, this will raise a flag and require a human involvement to resolve it. A conflict will be raised for any non identical warrants for the same day for the same inmate, because any such activity is suspicious and require additional attention.&lt;/p&gt;&lt;p&gt;Following the Single Responsibility Principle as applied to prison (there must be a single responsible party so we can put &lt;em&gt;them&lt;/em&gt; in jail if they mess this up), the validation of warrants is at the hands of the Registration Office and they take care of handling all such warrants. Even if the warrant was served directly to the block’s sergeant, the final validation (and responsibility) is on the Registration Office personal actually signing on the release form.&lt;/p&gt;</description><link>https://ayende.com/blog/182116-C/properly-getting-into-jail-didnt-we-already-see-this-warrant?Key=a5721965-49ed-420f-a955-51ab6f6e4e7f</link><guid>https://ayende.com/blog/182116-C/properly-getting-into-jail-didnt-we-already-see-this-warrant?Key=a5721965-49ed-420f-a955-51ab6f6e4e7f</guid><pubDate>Mon, 12 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: The workflow of getting an inmate released</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-workflow-_A4C9/image_2.png"&gt;&lt;img width="375" height="250" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-The-workflow-_A4C9/image_thumb.png" border="0"&gt;&lt;/a&gt;The whole point of having a prison is ensuring that the inmates are staying &lt;em&gt;in&lt;/em&gt;. As such, the process of actually getting an inmate out of the prison is quite involved. I’m using the release workflow as an obvious example, but there are many such workflows inside the prison that are similar. The inmate’s intake workflow, or disciplinary workflows or even just inmate’s transfers which can be quite complex (and typically also happen in big batches).&lt;/p&gt;&lt;p&gt;In the &lt;a href="https://ayende.com/blog/182114-C/properly-getting-into-jail-services-with-data-sharing-instead-of-rpc-or-messaging?key=30377850960e4a8183a6b5309e5e41ce"&gt;previous post&lt;/a&gt; in this series, I talked briefly about the idea of workflows as an event publication with multiple signatories to the workflow operation. If this make no sense, let me try to explain. &lt;/p&gt;&lt;p&gt;The trigger for starting an inmate’s release can be the acceptance of a warrant for immediate release, the expiration of the warrant to hold the inmate. There are several other variants (transfer to another facility, death of inmate, escape of inmate, etc) that are related but are not too relevant for the discussion, so I’ll just talk about the immediate release and the warrant expiration.&lt;/p&gt;&lt;p&gt;For warrant expiration, the workflow starts from the Registration Office publishing the list of inmates that are supposed to be released today. In technical terms, they create a series of workflow documents that are in the Open state and this gets disseminated to the rest of the system. Immediate release warrant is usually served to the Registration Office, but may also be served directly to the block’s sergeant. &lt;/p&gt;&lt;p&gt;If the Registration Office got the immediate release warrant, things are identical as the usual scheduled release (except that this might be served at any time). However, if this is served to the block’s sergeant, things are more interesting. At this point, it is the block that will initiate the workflow, but the overall responsibility for verifying the warrant and ensuring the actual release is still on the Registration Office. &lt;/p&gt;&lt;p&gt;As an aside, the notion of "who owns this” is quite important in the prison. Mostly because if you mess up, there might be consequences. This can be holding an inmate past the due date (bad, can result in damages paid to the inmate and career consequences to the person who messed up) to releasing an inmate that wasn’t supposed to be released (&lt;em&gt;really&lt;/em&gt; bad, sometimes it is not possible / feasible to hold them again, requires court approval, may end up in jail time for the person who messed up and also result in possible dangerous inmate being released). So the idea is that at any time, there is an owner for this process and a clear finger pointing at that person, “You’re to blame”. &lt;/p&gt;&lt;p&gt;Because of this, there are typically multiple steps in the release process. Consider the simple scenario of a scheduled release, we have:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Registering the inmate on the “to be released” list.&lt;/li&gt;&lt;li&gt;Notifying external and internal parties about this inmate’s pending release. For example, an inmate might have to go through a parole officer before actual release. This is done by sending the “to be released” list several days in advanced and getting at least an implicit agreement (by not vetoing / modifying the process) by external parties.&lt;/li&gt;&lt;li&gt;Verification that there are no explicit holds on the inmate. In the case of an inmate that is supposed to be deported, the inmate’s file will have an explicit “deport on release” which typically require coordinating with the border police to handle that. So the inmate can’t just be shoved out the door but handed off to someone. &lt;/li&gt;&lt;li&gt;Identification of the inmate at the block level. This is typically done on the sergeant’s level and then by an officer (preferably from the same block) that are familiar with the inmate and can validate that this is indeed the one to be released.&lt;/li&gt;&lt;li&gt;Checking out the inmate from the block level to the prison’s level. This explicitly remove the inmate from the block’s responsibility once the inmate has been handled off to the release queue.&lt;/li&gt;&lt;li&gt;Identification of the inmate by the Registration Office’s officer. This is a second verification that is done to ensure that there hasn’t been a mix up again.&lt;/li&gt;&lt;li&gt;Verification of the warrant to release the inmate and that there are no newer warrants that are in effect.&lt;/li&gt;&lt;li&gt;Returning of personal affects and getting the inmate’s signature that everything was properly returned.&lt;/li&gt;&lt;li&gt;Checking the inmate out of the prison, this step explicitly ends the period in which the now ex-inmate is held in prison.&lt;/li&gt;&lt;li&gt;Actually getting the newly released ex-inmate out of the prison. This can be to a family member at the gate or to a bus to the nearest city, etc.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I’m probably forgetting a few details in the middle, and there are branches for each and every one of these steps. &lt;/p&gt;&lt;p&gt;In terms of the technical details of how this works. The workflow document is being distributed throughout the system, and then various parties are now in charge of actually completing the various tasks in the workflow. For example, this may mean checking out the inmate’s personal affects from the safe in the morning, preparing for the release. So the steps aren’t necessarily in sequence or ordered. &lt;/p&gt;&lt;p&gt;The important thing is that the workflow document is published, and is now tracked. Typically, the release process is tracked by the Registration Office and the Command &amp;amp; Control Center. The Command &amp;amp; Control Center will typically be involved early in the process if an inmate isn’t released by the typical time, and the close of day process for the Registration Office includes verification that there aren’t any still pending inmate releases. &lt;/p&gt;&lt;p&gt;At any given point, we can track the process of the workflow from any point in the system (remember, changes are made locally and then distributed to the rest of the system). In there is a communication issue between different parts of the prison, that will typically show up as an alert that a particular workflow hasn’t been properly completed in the allotted time. At this point, external channel (walking &amp;amp; talking, usually) is used to verify the status of this particular inmate release. &lt;/p&gt;</description><link>https://ayende.com/blog/182115-C/properly-getting-into-jail-the-workflow-of-getting-an-inmate-released?Key=83b0cbc7-5b89-4d69-a69a-5719c1ac5761</link><guid>https://ayende.com/blog/182115-C/properly-getting-into-jail-the-workflow-of-getting-an-inmate-released?Key=83b0cbc7-5b89-4d69-a69a-5719c1ac5761</guid><pubDate>Fri, 09 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Services with data sharing instead of RPC or messaging</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Services-with_7853/image_2.png"&gt;&lt;img width="352" height="352" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Services-with_7853/image_thumb.png" border="0"&gt;&lt;/a&gt;The design of Macto (that is this prison management application I’m discussing) so far seems pretty strange. Some of the constraints are common, the desire for resiliency and being able to have each independent portion of the system work in isolation. However, the way we go about handling this is strange.&lt;/p&gt;&lt;p&gt;I looked up the definition of a micro services architecture and I got to &lt;a href="https://martinfowler.com/articles/microservices.html"&gt;Martin Fowler, saying&lt;/a&gt;:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;..the microservice architectural style &lt;a href="https://martinfowler.com/articles/microservices.html#footnote-etymology"&gt;[1]&lt;/a&gt; is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This wouldn’t work for our prison system, because we are required to continue normal operations when we can’t communicate with the other parts of the system. A prison block may not be able to talk to the Registration Office, but that doesn’t mean that it can error. Operations must continue normally.&lt;/p&gt;&lt;p&gt;So RPC over HTTPS is out, but what about messaging? We can use a queue to dispatch commands / events to the other parties in the system, no? &lt;/p&gt;&lt;p&gt;The answer is that we &lt;em&gt;can&lt;/em&gt; do that, but let’s consider how that will work. For events, that would work quite nicely, and have roughly the same model that we have now. In fact, with the RavenDB ETL process and the dissemination protocol in place, that is pretty much what we have. Changes to my local state are pushed via ETL to a shared known location and then distributed to the rest of the system.&lt;/p&gt;&lt;p&gt;But what about commands? A command in the system can be things like “we got a warrant for releasing an inmate”. That is something that &lt;em&gt;must&lt;/em&gt; proceed successfully. If there is a communication breakdown, generating an error message is not acceptable, in this case, someone will hand deliver the warrant to the block and get this inmate out of the prison. &lt;/p&gt;&lt;p&gt;In other words, we have the notion of commands flowing in the system, but the same command can also come from the Registration Office or from a phone call or from a lawyer physically showing up at the block and shoving a bunch of papers at the sergeant on duty demanding an immediate release. &lt;/p&gt;&lt;p&gt;All of this leads me to create an data architecture that is based on local data interaction with a backbone to share it, while relying on external channels to route around issues between parts of the system. Let’s consider the case of a releasing an inmate. The normal way it works is that the Registration Office prepare a list of inmates that needs to be released today. &lt;/p&gt;&lt;p&gt;Here is one such document, which is created on the Registration Office server.&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Services-with_7853/image_4.png"&gt;&lt;img width="600" height="661" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Services-with_7853/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This then flow via ETL to the rest of the prison. Each block will get the list of inmates that they need to process for release and the Command &amp;amp; Control Center is in charge that they are processed and released properly. I’ll have a separate post to talk about such workflows, because they are interesting, but the key here is that we don’t actually have a command being sent.&lt;/p&gt;&lt;p&gt;Instead, we create a document starting the workflow for release. This is exactly the same as an event being published and it will be received by the other parties in the prison. At this point, each party is going to do their own thing. For example, the Command &amp;amp; Control Center will verify that the bus to the nearest town is ordered and each block’s sergeant is in charge of getting the inmates processed out of the block and into the hand of the Registration Office, which will handle things such as returning personal effects, second verification that the right inmate is released, etc.&lt;/p&gt;&lt;p&gt;Unlike a command, which typically have a success / error code, we use this notion as well as timed alerts to verify that things happen. In other words, the Command &amp;amp; Control Center will be alerted if the inmate isn’t out of the prison by 10:00 AM and will take steps to check why that has happened. The Registration Office will also do its own checks at the close of the day, to ensure that no inmates are still in the prison when they shouldn’t. &lt;/p&gt;&lt;p&gt;Note that this involves multiple parties cooperating with each other, but none of them explicitly rely on request / response style of communication. &lt;/p&gt;&lt;p&gt;This &lt;em&gt;is&lt;/em&gt; message passing, and also event publication, but I find that this is a much more passive manner in which you’ll work. Instead of explicitly interacting with the outside world, you are always operating on your own data, and additional work and tasks to do shows up as it is replicated from the other parts of the system.&lt;/p&gt;&lt;p&gt;Another benefit of this approach is that it also ensures that there are multiple and independent verification steps for most processes, which is a good way to avoid making mistakes with people’s freedom. &lt;/p&gt;</description><link>https://ayende.com/blog/182114-C/properly-getting-into-jail-services-with-data-sharing-instead-of-rpc-or-messaging?Key=30377850-960e-4a81-83a6-b5309e5e41ce</link><guid>https://ayende.com/blog/182114-C/properly-getting-into-jail-services-with-data-sharing-instead-of-rpc-or-messaging?Key=30377850-960e-4a81-83a6-b5309e5e41ce</guid><pubDate>Thu, 08 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: The topology of sharing</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/image_5.png"&gt;&lt;img width="341" height="253" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the &lt;a href="https://ayende.com/blog/182081-C/properly-getting-into-jail-data-flow"&gt;previous post&lt;/a&gt;, I talked about the flow of data in the system and introduced the notion of sharing data via explicit ETL processes. The ETL process is an explicit contract of each part of the system that shares some of the data to the outside world. By the way, in the context of the prison system, the outside world is a bit misleading, it might be more accurate to say that we share the data with the other parties inside the prison. Nothing here is actually available outside the prison itself (integration with other systems, such as the Department of Justice, other prisons, etc is an even more complex topic that I don’t know if I’ll be covering. For now, assume that the method of integration if a Fax machine). &lt;/p&gt;&lt;p&gt;Here is the simplest topology that we can build using this approach. &lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/Snapshot_6.png"&gt;&lt;img width="417" height="389" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/Snapshot_thumb_2.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The Registration Office has an ETL process that outputs the data it wants to share with a dedicated database, specially for this purpose. From this public database, we setup replication to dedicated database instances on each of the blocks. &lt;/p&gt;&lt;p&gt;In other words, when the application inside the block wants to access some shared data, it isn’t going to reach over the network and hit the public registration database but use a local instance that the public registration database is replicating to. &lt;/p&gt;&lt;p&gt;Why do we have this behavior? Because we don’t trust the network and must always rely on our own local resources. When the network is available, we’ll get continuous updates via replication, and when it isn’t available, we’ll have the&lt;em&gt; &lt;/em&gt;latest information that we possibly could and can still act on that (I’ll have a separate post talking about workflow processes that mitigate eventual consistency and concurrency handling in such a system).&lt;/p&gt;&lt;p&gt;This means that the application can always continue running, regardless of the state of the outside world.&lt;/p&gt;&lt;p&gt;Another option, which is somewhat simpler, is to not have a public registration database, but a database that is there to share the data explicitly between all the different parties, this will look like this:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/Snapshot_10.png"&gt;&lt;img width="822" height="453" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-topologi_B340/Snapshot_thumb_4.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In this case, each party’s setup includes both the internal data that is required to running the block / office / department in question and a shared database that is used to hold all the data that is shared by all the parties in the prison.&lt;/p&gt;&lt;p&gt;Note that the topology of the shared data is a full mesh. In other words, data that is sent to the shared database from the Registration Office using RavenDB ETL will be sent to all the other parties, this is the same as we had before. However, because we now have a shared database, if the Registration Office cannot talk to Block B, that block will still get all the updates from Block A, including the updates that originated from the Registration Office. This is because RavenDB replication uses the gossip model and can bridge such gaps in network without issue.&lt;/p&gt;&lt;p&gt;This might be a simpler model, because the process of each party publishing information for the consumption of the rest of the prison is simplified, we simply define an ETL process to the shared database and the data will be distributed far and wide, made available to anyone that wants it.&lt;/p&gt;&lt;p&gt;This has the advantage that most of the details of managing services can be deferred to RavenDB. You need to make sure that your ETL processes are contractual, that is, they don’t change the shape or meaning of the data, and that is about it. All data access from the application is made to the local database and there is little need to worry about integration between the various parties, error handling of remote calls, etc.&lt;/p&gt;</description><link>https://ayende.com/blog/182113-C/properly-getting-into-jail-the-topology-of-sharing?Key=31912bdf-42e7-498c-908a-7fd7ebef1d77</link><guid>https://ayende.com/blog/182113-C/properly-getting-into-jail-the-topology-of-sharing?Key=31912bdf-42e7-498c-908a-7fd7ebef1d77</guid><pubDate>Wed, 07 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Data flow</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_2.png"&gt;&lt;img width="450" height="319" title="image" align="right" style="margin: 0px 0px 0px 10px; border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_thumb.png" border="0"&gt;&lt;/a&gt;In our prison system, we have a lot of independent parts, by design. Each of them is expected to work independently of the rest of the system, but also cooperate with them. That typically require a particular mindset when designing the application.&lt;/p&gt;&lt;p&gt;Let’s lay out the different aspects of integration between the various pieces, shall we?&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Each part of the system should be able to run completely independently from the other pieces.&lt;/li&gt;&lt;li&gt;There are offline methods for communications (literally a guy walking down to the block with a piece of paper) that can be a backup communication plane but can also by pass the system entirely (a warrant being served directly to the block’s officers). &lt;/li&gt;&lt;li&gt;There are two distinct options for communication: Commands (release this inmate, ensure inmate is ready to go to court at date) and notifications (inmates count, status, etc)&lt;/li&gt;&lt;li&gt;We trust, but verify, each piece of information that we receive.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The first point seems like a pretty standard requirement, but in combination of the second point, we get into a particularly interesting issue. We may have the same information entered into the system by multiple parties at different times.&lt;/p&gt;&lt;p&gt;For example, a warrant to release an inmate might be served directly to the block’s officer. The release is processed, and then the warrant arrives to the Registration office, which will also enter it. At some later time, this data is merged and we need to ensure that it make sense to the people reading it.&lt;/p&gt;&lt;p&gt;The offline communication plane is also a very important design considerations for a system that reflects the real world. It means that we don’t have to provide too complex an infrastructure for surviving production. In fact, given the fact that a prison is going to hardly have a top notch technical operations team (they might have a top notch &lt;em&gt;operations &lt;/em&gt;team, but they refer to something quite different), we don’t want to build something that rely on good communications.&lt;/p&gt;&lt;p&gt;To make sense of such a system, we need to define data ownership and data flow between the various systems. Because this is a really complex system, we’ll take a few example and analyze them properly. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;The legal status of an inmate.&lt;/li&gt;&lt;li&gt;The location of an inmate.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;What is the meaning of legal status? It means under what warrant it is in the prison (held until trial, 48 hours hold, got a final judgement). At its simplest, it is what date should this person be released. But in practical terms, this can be much more complex and may have conditions on where this inmate can be held, what they can do, etc. &lt;/p&gt;&lt;p&gt;Everything about the legal status of an inmate is the responsibility of the Registration Office. Any movements of inmates into or out of the prison must go through the Registration Office. Actually, this isn’t &lt;em&gt;quite &lt;/em&gt;true. Any movement of an inmate from the &lt;em&gt;responsibility&lt;/em&gt; of the prison must go through the Registration Office. But the physical location of the inmate is the responsibility of the block into which the inmate was assigned.&lt;/p&gt;&lt;p&gt;A good example of this would be an inmate that has been hospitalized. They are not physically inside the prison, but the prison is still responsible for them. The Registration Office doesn’t usually care for such details (but sometimes they do, for example, if the inmate has a court date that they’ll miss, they need to notify the court) because there isn’t a change in who is in charge of the inmate. &lt;/p&gt;&lt;p&gt;This is complex, but this is also the real world, and we need to manage this complexity. So, let’s define the ownership rules and data flow behavior:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Legal Status is owned by Registration Office and is being disseminated from there to all interested parties.&lt;/li&gt;&lt;li&gt;The location of an inmate and its current physical status are owned by the blocked it is assigned to and disseminated from there to all interested parties.&lt;/li&gt;&lt;li&gt;The assignment of an inmate to a particular block is also interesting. This piece of information is owned by the Registration Office, but it is not their (sole) decision. This may take a bit of explaining. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The block an inmate is assigned to is determined by a bunch of stuff. What is the legal status of the inmate, what is the previous / expected behavior of this inmate, whatever the inmate needs to be isolated from / together with certain people, information / recommendation from the intelligence office, court decisions, the free space available on each block, the inmate medical status and many other details that are not quite important. &lt;/p&gt;&lt;p&gt;The Registration Office will usually make the initial placement of where an inmate is going to go, but this is not their decision, there is a workflow involved that has input from way too many parties. The official decision is at the hands of the prison commander, but &lt;em&gt;recording&lt;/em&gt; this decision (and the data ownership of it) is at the hands of the Registration Office.&lt;/p&gt;&lt;p&gt;Okay, enough domain knowledge, let’s talk about the technical details, shall we? I’m sorry that I have to do such an info dump, and I’m trying to contain it to relevant pieces, but if I don’t include the semantics of what we are doing, it will make very little sense or be extremely artificial.&lt;/p&gt;&lt;p&gt;The legal status of inmates in the Registration Office needs to be sent to other parties in the prison. In particular, all the blocks and the Command &amp;amp; Control Center. &lt;/p&gt;&lt;p&gt;We can deal with this by defining the following RavenDB ETL process from the Registration Office:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_10.png"&gt;&lt;img width="646" height="601" title="image" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_thumb_4.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;What this does is simply define the data that we’ll share to the outside world. If I was building this for real, this will probably be a lot bigger, because an inmate is a really complex topic. What is important here is that we define this as an explicit process. In other words, this is part of the service contract that we have with the outside world. The shape of the data and the way we publish it may only be changed if we contact all parties involved. Practically speaking, this usually means that we can only add data, but never remove any fields from the system.&lt;/p&gt;&lt;p&gt;Note that in this case, we simplify the model as we send it out. The warrants for this inmate aren’t going out, and we just pull the latest status and release dates from the most up to date warrant. This is a good example of how we avoid exposing our internal state to the outside world, giving us the flexibility to change things later.&lt;/p&gt;&lt;p&gt;The question now is where does this data goes to? RavenDB ETL will write the data to an external database, and here we have a few options. First, we can define an ETL target for each of the known parties that want this data (each of the blocks and the Command &amp;amp; Control Center, at this time). But while that would work, it isn’t such a great idea. We’ll have to duplicate the ETL definition for each of those.&lt;/p&gt;&lt;p&gt;A better option is to send the (transformed) data to a dedicated database that will be our integration source. Consider the following example:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_6.png"&gt;&lt;img width="512" height="215" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_thumb_2.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In this case, we can have this dedicated public database that exposes all the data that the Registration Office shares with the rest of the world. Any part that wants this information can setup external replication from this database to their own. In this manner, when the Intelligence Office decides to make it known that they also needs to access the inmate registration data, we can just add them as a replication destination for this database.&lt;/p&gt;&lt;p&gt;Another option is not to have each individual party in the prison share its own status, but have a single shared database that each of them write to. This can look like this:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_8.png"&gt;&lt;img width="380" height="209" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Data-flow_A2FD/image_thumb_3.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In this case, any party that wants to share data will be writing it to the shared database, and anyone who reads it will have access to it through replication from there. This way, we define a data pipeline of all the shared data in the prison that anyone can hook up to.&lt;/p&gt;&lt;p&gt;This post is getting long enough that I’ll separate the discussion of the actual topology of the data and handling the incoming data to separate posts, stay tuned.&lt;/p&gt;</description><link>https://ayende.com/blog/182081-C/properly-getting-into-jail-data-flow?Key=727f8aeb-7a69-48fd-8af3-01f52fa01bf3</link><guid>https://ayende.com/blog/182081-C/properly-getting-into-jail-data-flow?Key=727f8aeb-7a69-48fd-8af3-01f52fa01bf3</guid><pubDate>Tue, 06 Mar 2018 08:47:00 GMT</pubDate></item><item><title>Properly getting into jail: it’s not a crime to be in an invalid state</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/image_2.png"&gt;&lt;img width="415" height="415" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/image_thumb.png" border="0"&gt;&lt;/a&gt;When you need to write a form, one of the first things that pops to mind is what kind of validations are required. A good example would be the new user registration form:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/Snapshot_2.png"&gt;&lt;img width="388" height="101" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/Snapshot_thumb.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is such an ingrained instinct that we typically seek to stop such invalid states as soon as possible. If the business rules says that you cannot have a certain state, it is easiest to just ensure that you can never get into such a state.&lt;/p&gt;&lt;p&gt;If you are working in a system that exists purely within the scope of your application, that might actually be useful property to have. This is certainly something that you want in your code, because it means that you can make assumptions on invariants. &lt;/p&gt;&lt;p&gt;If you have a system that reflects the real world, however, you need to take into account several really annoying things:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Your model of the real world is not accurate, and will never &lt;em&gt;be &lt;/em&gt;accurate.&lt;/li&gt;&lt;li&gt;The real world changes, sometimes quite rapidly and in a very annoying fashion.&lt;/li&gt;&lt;li&gt;Sometimes the invariant is real, but you gotta violate it anyway.&lt;/li&gt;&lt;li&gt;If the system doesn’t let the users do their job, they will do the job &lt;em&gt;in spite of your system&lt;/em&gt;. That will lead to a system of workarounds. Eventually, you’ll have to support these workarounds. This may result in hair loss and significant amount of aggravation.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Consider the case that the prison in question is a minimum security prison, expected to have white collar inmates that have already been tried. Now you get an inmate that is accused of murder and is currently on trial. (Side note, prisons have a very different structure for people who still undergoing trial, because they aren’t convicted yet and because the amount of pressure that they are under is very high. They’ll typically be held in different facilities and treated differently from inmates that have already been convicted and tried).&lt;/p&gt;&lt;p&gt;What do you think will happen if the system refuses to accept such an inmate into the prison? Well, the guy is &lt;em&gt;right there&lt;/em&gt;, and the prison commander has already authorized letting him in. So telling him that he should go back home because they “computer won’t let you in” is not going to be a workable solution. &lt;/p&gt;&lt;p&gt;Instead, we use a very different model for validation and acceptance of data. Instead of stopping the bad input as soon as possible, we raise a flag about it during processing, but we do allow the user to proceed, assuming they explicitly authorize this. It will look like this:&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/Snapshot_4.png"&gt;&lt;img width="501" height="283" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/Snapshot_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&lt;p&gt;At the same time, we flag such records and require additional review of the data.&lt;/p&gt;&lt;p&gt;In most cases, by the way, the fact that the inmate is in residence is not something that can be ignored and will be in all reports on the state of the prison until the state changes (transferred, verdict given, etc).&lt;/p&gt;&lt;p&gt;This kind of thinking is important, because it means that the software intrinsically does not trust the data, but continue runs validation on it. This is a good practice to be in when dealing with systems that reflect the real world.&lt;/p&gt;&lt;p&gt;This does lead to an interesting question, where do we run these validations, and when?&lt;/p&gt;&lt;p&gt;The ground rules for a good application is that it is like an amoeba, it may have multiple locations that it accepts input, but that is the only way to push data in, through well defined channels.&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/image_4.png"&gt;&lt;img width="245" height="238" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-its-not-a-cri_DF7A/image_thumb_1.png" border="0"&gt;&lt;/a&gt;This is another way of saying that we don’t allow someone else to go and poke around in our database behind our back.&lt;/p&gt;&lt;p&gt;Any time that we accept new data, regardless of the channel it arrives in, we run it through the validation pipeline. And this validation pipeline can add (or mark as obsolete) validation issues that should be brought to the attention of the people in charge.&lt;/p&gt;&lt;p&gt;Note that these sort of validations are almost always very much business rules, not type issues. If someone’s birthday is in the future, you can feel free to very easily reject that data as purely invalid. But if someone’s release date is in the past, however, you might still need to accept them as an inmate (the paperwork are really in the mail, sometimes). &lt;/p&gt;&lt;p&gt;I think I’ll need another post just to talk about how to implement these validation rules and behaviors, but that is still down the line. The next post topic is going to be data flow between the different systems that we talked about so far. &lt;/p&gt;</description><link>https://ayende.com/blog/182050-A/properly-getting-into-jail-its-not-a-crime-to-be-in-an-invalid-state?Key=26e10876-9178-4089-b86c-0ebc9afe3532</link><guid>https://ayende.com/blog/182050-A/properly-getting-into-jail-its-not-a-crime-to-be-in-an-invalid-state?Key=26e10876-9178-4089-b86c-0ebc9afe3532</guid><pubDate>Fri, 02 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Physical architecture</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Physical-arch_C71D/image_2.png"&gt;&lt;img width="374" height="167" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail-Physical-arch_C71D/image_thumb.png" border="0"&gt;&lt;/a&gt;When building a system for a prison you need to consider a few more levels of high availably than usual. In particular, you might need to operate while there are riots in progress, which may be prison wide, in a single block or section or in general while in a partial failure mode. Regardless of what is going on, you want maximum survivability for the system. If there is a riot in the next block, I still want to be able to do a proper count of the inmates in &lt;em&gt;this &lt;/em&gt;block, for example. So each block must be able to operate independently from the others.&amp;nbsp; For that matter, the command &amp;amp; control center must always be operational and so does the medical ward, the registration (who is in the prison right now is something that is important to know &lt;em&gt;especially&lt;/em&gt; when there are issues. &lt;/p&gt;&lt;p&gt;All of this means that we can’t rely on any centralized architecture and that we want maximum separation between the different pieces. The reason this post is titled physical architecture is just that, we are talking about physical machines that reside some distance from one another. Now, granted, prisons are, by their very nature, limited in size, so we don’t have to worry too much about the latency of calls. However, we are worried about other aspects. We have to assume low to no maintenance and the chance of riots / floods and possible locusts. &lt;/p&gt;&lt;p&gt;The best case scenario for us is that each server will be installed on its own block, with a UPS&amp;nbsp; if we are lucky. The whole thing residing in a locked cupboard in the block’s sergeant's office. Given typical conditions, the cupboard is also were the teapot and coffeemaker will reside, and we’ll have to worry about our server going doing because someone spilled a whole pot of tea on the machine.&amp;nbsp; But I’ll leave &lt;em&gt;completely fictional heart &lt;/em&gt;attack inducing events to another day and focus on the software architecture. &lt;/p&gt;&lt;p&gt;We need to be able to operate each block independently of other blocks and from the central prison administration. That means that we will use an architecture that assumes that we are an island. All the applications that are used will only talk to a local database, and cannot assume any other connectivity being available. &lt;/p&gt;&lt;p&gt;Instead, we’ll build explicit data flow channels between the different parts of the system and handle that part explicitly. &lt;/p&gt;&lt;p&gt;It is important to note that this type of architecture also has another major benefit, it cushions certain type of errors. If an inmate managed to trip on a wire and cut the network cable leading to the block, we want to still be able to operate normally for all / most usual things. This means that we can summon the network guy to come and fix things in the morning, rather than have them come up &lt;em&gt;now&lt;/em&gt;. That is the kind of architectural results that you like if you are one of the guys who might be called in such a case.&lt;/p&gt;&lt;p&gt;The block server will hold:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The inmates that are in the block and well as their record in the block (disciplinary actions, privileges withheld / given, notes, etc).&lt;/li&gt;&lt;li&gt;Records of counting of inmates.&lt;/li&gt;&lt;li&gt;Log of actions happening in the block (Sargent's diary).&lt;/li&gt;&lt;li&gt;Tasks and operations required (sending inmates to court, scheduled work parties, cell searches, etc)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;That kind of data is essential for the routine operation of the block and should always be available. &lt;/p&gt;&lt;p&gt;At the prison’s level, you have all kind of departments and the kind of data they need to keep:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Medical – medical history and other medical stuff. This is a separate system, because there is nothing unique in a prison medical ward that require anything special other than the bars on the windows and better locks on the drug cabinets. &lt;/li&gt;&lt;li&gt;Registration – all the inmates in the prison as well as all their holding documents. These are the documents and authorization to withhold someone’s freedom, and it is stored and managed by this department. This is also the department that can generate work orders (send this inmate to this court) for the rest of the prison and is the primary outside contact.&lt;/li&gt;&lt;li&gt;Command &amp;amp; control center – has a view of everything and is in charge of tracking operations, but the only action it takes is to pass that information onward.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I’ll speak more about each of these departments at length in the future, but for now I want to focus on something that is very interesting. None of these departments actually need to talk to anyone else to do most of its job.&lt;/p&gt;&lt;p&gt;The C&amp;amp;C center needs to get reports from the blocks about counts, that inmates were sent to court, that the inmates that were supposed to be freed were actually freed, etc. But none of that &lt;em&gt;has&lt;/em&gt; to happen through regular channels. In fact, in many cases, they’re multiple channels that are used on an ongoing basis. &lt;/p&gt;&lt;p&gt;In addition to having the block’s server notify the C&amp;amp;C systems that the counts were completed, the sergeant will also notify C&amp;amp;C directly via a phone call about the count and how many inmates are currently in residence in the block. &lt;/p&gt;&lt;p&gt;The prison software needs to record all of that. In fact, even though it looks like it is doing the same work twice, we &lt;em&gt;need&lt;/em&gt; it to happen, for the same reason we have double entry book keeping. It helps catch issues and omissions.&lt;/p&gt;&lt;p&gt;So that leads to another architectural tenant for the system. Not only are the system made of physically separated components, but we are also considering each portion of the system as a consistency boundary.&lt;/p&gt;&lt;p&gt;I hesitated here with regards to the naming. I almost went with a security boundary, but that isn’t quite right. It isn’t that the other side is not trusted in the classic sense. They are trusted, but they aren’t &lt;em&gt;verified&lt;/em&gt;. We’ll need to double check all such data as it goes into the system. But that leads to the next big challenge, how are we going to handle the flow of data and verification of the data across the system as a whole. &lt;/p&gt;&lt;p&gt;I think this post is long enough as it is, so I’ll keep that for the next one.&lt;/p&gt;</description><link>https://ayende.com/blog/182049-A/properly-getting-into-jail-physical-architecture?Key=0670af58-6ce1-46c0-a97c-7ee74a37f028</link><guid>https://ayende.com/blog/182049-A/properly-getting-into-jail-physical-architecture?Key=0670af58-6ce1-46c0-a97c-7ee74a37f028</guid><pubDate>Thu, 01 Mar 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Counting Inmates and other hard problems</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/image_2.png"&gt;&lt;img width="277" height="176" title="image" align="right" style="border: 0px currentcolor; border-image: none; float: right; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/image_thumb.png" border="0"&gt;&lt;/a&gt;In prison, the notion of counting people is sacred. This is probably because the whole &lt;em&gt;point &lt;/em&gt;of having a prison is to keep the people you put in there inside, and that means that you count inmates, multiple times a day.&lt;/p&gt;&lt;p&gt;The dirty secret, however, is that you almost never get to that perfect occupancy number, where all the inmates that are registered to a particular block are actually &lt;em&gt;in&lt;/em&gt; that block. In most cases, you have at least a few that are outside the block (court dates, medical issues with offsite care, visitations, outside work, etc).&lt;/p&gt;&lt;p&gt;So the key here is not just to count the inmates, but to also &lt;em&gt;account&lt;/em&gt; for them. Let’s consider how this will look like in the user interface for counting a couple of cells, shall we?&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/Snapshot_4.png"&gt;&lt;img width="201" height="261" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/Snapshot_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This works, but it isn’t a good idea. Named counts are usually reserved for the first / last counts of the day. During the day, because it is so frequent to have inmates in and out of their assigned location, you’ll usually do things differently. You’ll have a total count of inmates in the block, and a list of the exceptions. That would look something like this:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/Snapshot_8.png"&gt;&lt;img width="410" height="374" title="Snapshot" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="Snapshot" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/Snapshot_thumb_3.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;You have the number of inmates in the block, how many are expected to be there, the actual count as verified by the sergeant’s signature and the named list of inmates that are not currently in the block. You might have noticed that we are carefully tracking who is responsible for any inmate that it currently out of the block. This is because that matters (for a whole host of legal and cover your ass reasons).&lt;/p&gt;&lt;p&gt;So how would we build such a system? &lt;/p&gt;&lt;p&gt;To start with, we need to talk about the current component or service that we are building. The notion of counting is typically done at the block level, so we’ll start by modeling things there. We’ll have the Block Service, which is in charge of managing anything that is going on inside the block. &lt;/p&gt;&lt;p&gt;A block is composed of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Cells, to which inmates are assigned. This is typically an internal division only that has no real business meaning.&lt;/li&gt;&lt;li&gt;Inmates, which are quite important.&lt;/li&gt;&lt;li&gt;Staff, which is probably a separate issue entirely, but is quite important for thing such as having enough people at hand to do things like actually run the block. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In terms of the actual operations we need to do, the block is managed by at least a single Sargent per shift and multiple guards. The Sargent is responsible for handling incoming inmates, counting all inmates multiple times a day and other things that we won’t be tracking on a computer system. The guards will mostly interact with the system when they need to check an inmate out for whatever reason (such as taking them to a checkup by a nurse).&lt;/p&gt;&lt;p&gt;With all of this information, we can now model the data we have for a block. Here is the most important document we have, the block’s population. There are a few things here that are worth exploring in the design of the document:&lt;/p&gt;&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/image_4.png"&gt;&lt;img width="527" height="501" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Properly-getting-into-jail_9AF0/image_thumb_1.png" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;First, we have a separate document per date, recording the state of the block’s population at that time. This is important, because we need to be able to go back in time and track such things. You can also see that the document contains a lot of data that has both the name and id. Why is that?&lt;/p&gt;&lt;p&gt;The information recorded on this document is the data as it was &lt;em&gt;at the time of this document’s creation&lt;/em&gt;. Later changes do no apply, by design, since we need to see keep it at the state it was at the time.&amp;nbsp; It might be easier to look at things in code:&lt;/p&gt;&lt;blockquote&gt;&lt;script src="https://gist.github.com/ayende/be842e0f143dda15d535a53f12349fd2.js"&gt;&lt;/script&gt;&lt;/blockquote&gt;&lt;p&gt;The most important thing here is the notion of the Log, which records every incoming and outgoing inmate from the block. &lt;/p&gt;&lt;p&gt;In addition to the daily’s block population document, we also have three to five counting documents, which are built on top of it. These reflect the actual counts made plus the listing of inmates that aren’t currently in the block and why. &lt;/p&gt;&lt;p&gt;And that is quite enough about the prison’s life. This give us sufficient level of details that we can now work with. The next post will talk about how the physical architecture and data flow in the prison.&lt;/p&gt;</description><link>https://ayende.com/blog/182018-C/properly-getting-into-jail-counting-inmates-and-other-hard-problems?Key=6fbdb2d6-8505-4f50-a094-a73d57925159</link><guid>https://ayende.com/blog/182018-C/properly-getting-into-jail-counting-inmates-and-other-hard-problems?Key=6fbdb2d6-8505-4f50-a094-a73d57925159</guid><pubDate>Wed, 28 Feb 2018 10:00:00 GMT</pubDate></item><item><title>Properly getting into jail: Introduction &amp; architecture</title><description>&lt;p&gt;&lt;a href="https://ayende.com/blog/Images/Open-Live-Writer/Get_91A9/image_2.png"&gt;&lt;img style="border: 0px currentcolor; float: right; display: inline; background-image: none;" title="image" src="https://ayende.com/blog/Images/Open-Live-Writer/Get_91A9/image_thumb.png" alt="image" width="391" height="206" align="right" border="0" /&gt;&lt;/a&gt;I have been writing about the internals of RavenDB for quite a while, and it is fascinating in many respects, but it gets tiring to keep thinking about bits &amp;amp; bytes all the time. I&amp;rsquo;m missing writing some of the more high level stuff, in particular about software architecture. So I thought that I would take the time to resurrect a very old post series of mine, &lt;a href="https://ayende.com/blog/4087/macto-or-how-to-build-a-prison"&gt;Macto&lt;/a&gt;. I actually have &lt;a href="https://ayende.com/blog/tags/macto"&gt;quite a few posts&lt;/a&gt; about this, but they are all close to a decade old, so I might as well start from scratch.&lt;/p&gt;
&lt;p&gt;Macto is a sample app for managing a prison. This is one of the few areas in which I can be an expert on the business requirements that isn&amp;rsquo;t utterly boring (I don&amp;rsquo;t want to do yet another E-Commerce stuff).&amp;nbsp; To keep up with the times, Macto is going to be written with a Micro service architecture, and just for fun, I might be doing that in multiple languages and platforms, because prison is not fun, and neither should be working on it&amp;rsquo;s computing systems &lt;img class="wlEmoticon wlEmoticon-smile" src="https://ayende.com/blog/Images/Open-Live-Writer/Get_91A9/wlEmoticon-smile_2.png" alt="Smile" /&gt;. Oh, and there is also the real world thing, I guess.&lt;/p&gt;
&lt;p&gt;Since 2009, I have pretty much given up on building anything UI wise, so I&amp;rsquo;m going to show a few mockup screens, but the idea is that I&amp;rsquo;m going to be looking only at backend code, with another team actually doing the user interface.&lt;/p&gt;
&lt;p&gt;The first thing to start with, I guess, is to paint the overall architecture of the system. Prisons are pretty rigid systems, as you might expect, but there are a &lt;em&gt;lot&lt;/em&gt; of interconnected parts. In order to properly build a system to manage a prison we need to be able to answer what is going on from multiple points of view and from very different perspectives.&lt;/p&gt;
&lt;p&gt;The prison commander cares about such things as the inmate&amp;rsquo;s count (&lt;em&gt;the&lt;/em&gt; job is to keep them all hale and accounted for). The individual guard care about the particular set of cells they are assigned to and the inmates in them. The guys at Registrations care about the legal details of having a lawful warrant for holding an inmate in prison as well as when an inmate should be released. Intelligence cares about the connections between inmates, the kind of heads up that came through channels and what kind of actions should be taken as a result. Medical needs to verify that incoming inmates are fit to be held in the facility and Transfers needs to ensure that any movements of inmates outside the prison will complete successfully (as in, you got them out, you also gotta bring them &lt;em&gt;all&lt;/em&gt; in).&lt;/p&gt;
&lt;p&gt;Each of those pieces interact with others in interesting and complex ways. For example, incoming inmates needs to go through Registration for legal paperwork, Medical for certification, Intelligence for verification and then assigned to the proper block.&amp;nbsp; Once they are accepted into the prison, they are the charge of the particular block they are assigned to and rarely need to interact with the rest of the prison unless something extraordinary happens (visits, court, sickness, etc).&lt;/p&gt;
&lt;p&gt;When thinking about the software architecture of such a system, the most important rule to remember is that we want the system to be &lt;em&gt;used&lt;/em&gt;, this means that we really need to plan for what people are actually doing (in abstract of what they &lt;em&gt;should&lt;/em&gt; be doing) and to help them do things, rather than hinder them. In most places, all these details are done with pen &amp;amp; paper, and it works, so our system will have to offer something more. Not to the prison administration, but to the actual people going about their work with the inmates.&lt;/p&gt;
&lt;p&gt;From a software architecture point of view, we are going to model the system as a set of independent services that will each have the role of one of the departments inside the prison. The current term in micro-services, but in real systems, they are not so micro, so we might need to repeatedly break things apart until we get to a level in which things make sense in isolation.&lt;/p&gt;
&lt;p&gt;A lot of the complexity is involved in managing such a system is in the flow of information across the system. In a prison, this is the responsibility of the Command &amp;amp; Control Center (C3, from now on) which is in charge of coordination and monitoring of actions across the board. This also work very closely with the heads of all departments and the prison commander as well as most other external parties, but it generally does nothing on its own.&lt;/p&gt;
&lt;p&gt;I think that this is enough of an intro, and we&amp;rsquo;ll get right on to things in the next post, where we&amp;rsquo;ll talk about Counting Inmates.&lt;/p&gt;</description><link>https://ayende.com/blog/182017-C/properly-getting-into-jail-introduction-architecture?Key=627691dc-52f5-444c-89b4-2a07323412b4</link><guid>https://ayende.com/blog/182017-C/properly-getting-into-jail-introduction-architecture?Key=627691dc-52f5-444c-89b4-2a07323412b4</guid><pubDate>Tue, 27 Feb 2018 10:00:00 GMT</pubDate></item><item><title>Macto: Looking at warrants</title><description>&lt;p&gt;After spending so much time talking about how important Warrants are, it is actually surprising to see the UI for a warrant:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_thumb_2.png" width="638" height="800"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It is pretty simple, because from a &lt;em&gt;data entry &lt;/em&gt;perspective, there isn’t really much to it. It is the effects of the Warrants that make it such an interesting concept. One thing to note here is that the date that we care about for the Warrant isn’t the date it was issued, but when the guy was actually arrested, that is where the clock starts ticking.&lt;/p&gt; &lt;p&gt;Adding a Warrant is also not that complex from a data entry perspective:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_thumb_3.png" width="710" height="519"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_thumb_4.png" width="710" height="519"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Look-at-warrants_F744/image_thumb_5.png" width="710" height="519"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As you can see, thus far, it is pretty simple. But when you click the Finish button the complexity starts.&lt;/p&gt; &lt;p&gt;We need to check that the Warrant is valid (issued by someone with the authority to do so), and then calculate the new duration for the Inmate.&lt;/p&gt; &lt;p&gt;And that is enough for today, I just wrote ~10 posts on Macto in the last 24 hours, it is time to do something else.&lt;/p&gt;</description><link>https://ayende.com/blog/57345/macto-looking-at-warrants?Key=42e6de5c-7a27-4add-8003-c9b4cce0ae3b</link><guid>https://ayende.com/blog/57345/macto-looking-at-warrants?Key=42e6de5c-7a27-4add-8003-c9b4cce0ae3b</guid><pubDate>Wed, 17 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: Talking to nasty people</title><description>&lt;p&gt;Well, so far we have looked at the main screen and the Counting screen, it is time we introduce ourselves to the Inmate screen as well:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/80d58be13973_EC6E/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/80d58be13973_EC6E/image_thumb_3.png" width="800" height="542"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As you can see, there isn’t a lot going on here. We have the Inmate’s Id, name and location (including noting where he is located, if he is known to be outside the prison). We don’t usually care for things like detailed information in the normal course of things (the Inamte’s national id, for example). That information is important, but usually not relevant, we relegate it to a separate screen.&lt;/p&gt; &lt;p&gt;The dates for incarceration and scheduled release are also important, but they aren’t available for editing, they are there only for information purposes.&lt;/p&gt; &lt;p&gt;The note is there to make sure that highly important information (such as whatever the Inmate is suicidal / flight risk) would be clearly available. The same is true for the Cliff Notes version of the Record.&lt;/p&gt; &lt;p&gt;It is there not for casual use, but to ensure that pertinent information is available. Most importantly, note the last line there. Which means that if this Inmate is about to be released, we have to notify someone and get their approval for that. Well, approval is a strong word, we notify them that they need to give us a new Warrant for the Inmate, but we can delay releasing him (say, until midnight the day he is to be released) waiting for that Warrant.&lt;/p&gt; &lt;p&gt;Warrants are important, and you can see the ones that this guy have listed here. The last Warrant is the important one, the others are shown for completion sake and to ensure that we have continuous Warrants.&lt;/p&gt; &lt;p&gt;There are also several actions that we can do to an Inmate. We can Transfer him to another prison, Release him or Add a Warrant. Each of those is a complex process of its own, and I’ll discuss them later on.&lt;/p&gt;</description><link>https://ayende.com/blog/56321/macto-talking-to-nasty-people?Key=0dd16d00-50ca-4674-a68c-4fd165911d5b</link><guid>https://ayende.com/blog/56321/macto-talking-to-nasty-people?Key=0dd16d00-50ca-4674-a68c-4fd165911d5b</guid><pubDate>Mon, 15 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: Counting is The Holy Grail</title><description>&lt;p&gt;I might have mentioned before that Counting is somewhat important in prison. That is about as accurate as saying that you would somewhat prefer it to keep breathing. Counting is the heartbeat of the prison, &lt;em&gt;the &lt;/em&gt;thing that the entire operation revolves around.&lt;/p&gt; &lt;p&gt;Here we can see the counting screen:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Counting-is-The-Holy-Grail_E0FA/image_3.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macto-Counting-is-The-Holy-Grail_E0FA/image_thumb.png" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can see that we have an Open Count here, that is a count that is still in progress. Some cell blocks have reported their counts, and some are still in the process of making the count.&lt;/p&gt; &lt;p&gt;A Count is Closed when we know where are the Inmates are. (When the two numbers line up properly). You probably noticed that there are two ways to report a count, the first is for Inmates who are outside the prison (court, hospital, etc). Because they are outside the prison, we track them by name. For internal counts, we don’t really care about names, just the numbers.&lt;/p&gt; &lt;p&gt;There is another type of a Count, a Named Count, which is a process that happen very rarely, but is usually used to reconcile what is in the computer and what is actually in the cells. &lt;/p&gt; &lt;p&gt;It is important to understand the “Officer in charge” field, basically, it is the guy who has the legal responsibility and is signing off on those numbers. In other words, if there is something wrong, that guy is going to take a hard fall.&lt;/p&gt;</description><link>https://ayende.com/blog/55297/macto-counting-is-the-holy-grail?Key=bf71863c-133f-4878-9421-1a9be25f546c</link><guid>https://ayende.com/blog/55297/macto-counting-is-the-holy-grail?Key=bf71863c-133f-4878-9421-1a9be25f546c</guid><pubDate>Thu, 11 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: Getting Started, you never forget your first Inmate</title><description>&lt;p&gt;People always love to start with CRUD, but it is almost never that simple. In this post, we will review the process required to accept an Inmate into the prison.&lt;/p&gt; &lt;p&gt;That process is composed of the following parts:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Identification  &lt;ul&gt; &lt;li&gt;Who is the guy?  &lt;li&gt;Id number  &lt;li&gt;Names  &lt;li&gt;Photo  &lt;li&gt;If we can’t identify / refuse to identify, we still need to be able to accept him.&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Lawful chain of incarceration  &lt;ul&gt; &lt;li&gt;Go over all the documents for his arrest  &lt;li&gt;Ensure that they are all in order  &lt;li&gt;Ensure that they are continuous and valid  &lt;li&gt;Check if there are any urgent things to do with him. For example, he may need to be at court today or the next day.&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Medical exam  &lt;ul&gt; &lt;li&gt;Is it okay to hold the guy in prison?  &lt;li&gt;If he is not healthy, can we take care of him in prison?  &lt;li&gt;Does he require hospitalization?  &lt;li&gt;Does he require medicine / treatment?  &lt;li&gt;Are there any medical consideration into where to put him?&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Intelligence  &lt;ul&gt; &lt;li&gt;Interviewing the guy  &lt;li&gt;Report interesting details that are known about him&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Acceptability  &lt;ul&gt; &lt;li&gt;Does he fit the level of Inmates we can accept? We usually don’t put murderers in minimum security prisons, for example.  &lt;li&gt;Does he have any medical reason to reject him?  &lt;li&gt;Are there any problems with the incarceration documents?  &lt;li&gt;Is there any intelligence warning about the guy?&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Placement  &lt;ul&gt; &lt;li&gt;Decide where to put the Inmate  &lt;li&gt;What type of an Inmate is he? (Just arrested, sentenced, sentenced for a long period, etc)  &lt;li&gt;Why is he in prison for?  &lt;li&gt;What kind is he? (You want to avoid Inmate infighting, it creates paperwork, so you avoid putting them in conflict if possible)  &lt;li&gt;Where there is room available?&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Another important aspect to remember is that while we are allowed to reject invalid input (for example, we are allowed to say that the id number has to consist of only numeric characters), we are &lt;em&gt;not&lt;/em&gt; allowed to reject input that is wrong.&lt;/p&gt; &lt;p&gt;What do I mean by that. Let us say that we have an Inmate at the door, and he doesn’t have his incarceration paperwork in order (well, not &lt;em&gt;he&lt;/em&gt;, whoever brought him in, but you get the point). That means that legally, we can’t hold him. But Macto isn’t where things are actually happening, it is merely a support system that tracks what is going on in the real world. And the prison commander can decide to accept that guy anyway (say, because the paperwork in en route), and we have to allow for that. If we try to stop people from doing this, it is going to be worked around, and we don’t want that. The system is allowed, even encouraged, to warn the users when they are doing something wrong, but it &lt;em&gt;cannot&lt;/em&gt; block it.&lt;/p&gt; &lt;p&gt;The first part, Identification, is actually pretty easy, all told. This is fairly simple data entry process. We’ll want to do &lt;em&gt;some&lt;/em&gt; checkups on the data, such as that the id number is valid or to check the id against the name, etc. But we basically have to have some level of trust in the documents that we have. You usually don’t have an arrest warrant for “tall guy in brown shirt”. If we find any problems there, we can Flag the Dossier as a potentially fraudulent name. This is also the stage where we want to check if the Inmate is a returned visit, and bring the life the old Dossier. &lt;/p&gt; &lt;p&gt;The second part is more complex, because there are many different types of Warrants, each with their own implications. Arrest Warrant is valid for 24 hours, Remand Warrant is good until sentencing, etc. We need to input all of those Warrants, ensure that they are consistent, valid and continuous. If there is a problem with that, we need to Flag the Dossier, but we can’t reject it. We will discuss this in more detail in the next post.&lt;/p&gt; &lt;p&gt;The third part is basically external to Macto, we may need to provide the Inmate ID, for correlation purposes, but nothing beyond that. We do need to get approval from the doctor that the Inmate is in an OK condition to be held in the prison. That &lt;em&gt;does&lt;/em&gt; get recorded in Macto.&lt;/p&gt; &lt;p&gt;The forth part is again, external to us. Usually any information is classified and wouldn’t appear in Macto. We may get some intelligence brief about the guy, but usually we won’t.&lt;/p&gt; &lt;p&gt;The fifth part is &lt;strong&gt;important&lt;/strong&gt;, this is where we actually take legal and physical ownership for the Inmate. Up until that point, we had him in our hands, but we weren’t responsible for him. Accepting the Inmate is a simple matter if everything is good, but if the Dossier was Flagged, we might need approval from the officer in charge. Accepting an Inmate means that he is added to the prison’s Roster. &lt;/p&gt; &lt;p&gt;The sixth part is pretty much “where do I have a spare bed”, after which he is added to the Roster of the cell block he is now in care of.&lt;/p&gt; &lt;p&gt;It is important to note that Placement &lt;em&gt;always &lt;/em&gt;happens. Even if immediately after Accepting an Inmate you rushed him to the hospital, that Inmate still has to be assigned to a cell block, because that assignment means that the cell block commander is in charge of him. That way we avoid potential mishaps when an Inmate is assigned to no one, doesn’t get Counted.&lt;/p&gt; &lt;p&gt;Okay, I think that this is enough for now, in the next post, we will discuss what exactly goes on in the second part, it is a pretty complex piece, and it deserve its own post.&lt;/p&gt;</description><link>https://ayende.com/blog/51201/macto-getting-started-you-never-forget-your-first-inmate?Key=2170a0c6-6d5d-40bf-ad14-ef89e59890c4</link><guid>https://ayende.com/blog/51201/macto-getting-started-you-never-forget-your-first-inmate?Key=2170a0c6-6d5d-40bf-ad14-ef89e59890c4</guid><pubDate>Wed, 10 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: The Main Screen</title><description>&lt;p&gt;I usually like to think about the responsibilities of the system by showing up the UI. It is a great way to communicate with both customers and developers.&lt;/p&gt; &lt;p&gt;Here is the main screen for the application:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Macot_D265/image_5.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Macot_D265/image_thumb.png" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is actually a bad place to start with, in terms of coding start points, because it requires so many other things as well. This particular screen is likely to be viewed pretty much everywhere, this is what the prison commanders and the cell blocks commanders have at their desktop, what the officers are using to do their daily work (usually for Counting, admittedly).&lt;/p&gt; &lt;p&gt;Even before we can start , it reveals quite a lot about the actual way things work. In this screen, we can see that we have Flagged Dossiers, those are Inmates that have some problem with their Dossier. We can accept Inmates with problematic Dossiers, but we want to fix that as soon as possible, so we make this something that is very much front and center.&lt;/p&gt; &lt;p&gt;The “Action required” section detail Inmates that we have to take some action about. Whatever it is a court date that this inmate have to be at or his sentence is ending or a warrant that need extending. &lt;/p&gt; &lt;p&gt;Finally, and most importantly, we have the counts, which are &lt;em&gt;the&lt;/em&gt; most important thing in the prison. You can see that the numbers at the bottom line up. If they don’t, we have A Problem.&lt;/p&gt;</description><link>https://ayende.com/blog/54273/macto-the-main-screen?Key=4104a788-7814-4244-9c6e-fa1ae1f61b98</link><guid>https://ayende.com/blog/54273/macto-the-main-screen?Key=4104a788-7814-4244-9c6e-fa1ae1f61b98</guid><pubDate>Mon, 08 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: Warrants are for fools</title><description>&lt;p&gt;Warrants are kinda important in a prison. They are the legal authority to limit someone’s freedom. In wouldn’t be overstating the fact in saying that Warrants are one of the major factors being managed in Macto.&lt;/p&gt; &lt;p&gt;There are all kind of Warrants in existence. To list just a few of them:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Arrest Warrant – Issued by an officer, generally hold for 24 hours only.&lt;/li&gt; &lt;li&gt;Detention Warrant – Issued by the court, generally for a short amount of time, up to a few weeks, in most cases.&lt;/li&gt; &lt;li&gt;Remand Warrant – Issued by the court, generally instructing the prison to hold the Inmate in custody until sentencing (not limited in time).&lt;/li&gt; &lt;li&gt;Sentencing Warrant – Issued by the court, specifying the total time that an Inmate is to be incarcerated.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;There are other warrants, such as an Court Arrest Warrant, for example, but for the purpose of Macto, we won’t get into those. The type of activity currently required by the prison doesn’t really need them, but that might change in the future.&lt;/p&gt; &lt;p&gt;There is also another type of Warrant available, it is Whatever The Judge Said Warrant, or as the lawyers call is Mandamus Warrant. It is basically an instruction to do something, and it can be just about anything. From letting the Inmate to call his wife to putting him in a different cell or transferring him to a different prison to command special food / treatment to… Well, there is a reason I call it Whatever The Judge Said.&lt;/p&gt; &lt;p&gt;The rules for Warrants for incarceration are pretty simple. Each warrant type has an issuer (Arrest Warrants can only be given by Officers of rank Captain and above) for a certain duration (which in some cases, may be limited, such as the 24 hour limit for Arrest Warrants). Depending on the type of Warrant, it can be in Hours, Days, Months or Years. The units in which a warrant is specified are &lt;em&gt;very&lt;/em&gt; important. In particular, there is a difference between 30 days incarceration and 1 month incarceration, for example. And hourly Warrants &lt;em&gt;requires&lt;/em&gt; that by the time the Warrant expire, you are either got a new one at court or let the Inmate go.&lt;/p&gt; &lt;p&gt;The last issued Warrant is always the one that is valid, and all Warrants must be continuous. Gaps in the middle are considered to be a &lt;em&gt;Very Bad&lt;/em&gt; thing.&lt;/p&gt;</description><link>https://ayende.com/blog/53249/macto-warrants-are-for-fools?Key=6a1a28e6-103a-4c56-8cf0-1b5074816e55</link><guid>https://ayende.com/blog/53249/macto-warrants-are-for-fools?Key=6a1a28e6-103a-4c56-8cf0-1b5074816e55</guid><pubDate>Wed, 03 Aug 2011 09:00:00 GMT</pubDate></item><item><title>Macto: Non functional concerns, you are a legal system</title><description>&lt;p&gt;Macto is a system that operates in a highly legislative environment. As such, we have to be prepared for the court to ask us to show our records about a particular Inmate. Part of that is ensuring that we preserve the history of the Inmate’s Dossier. An example where this would be relevant is when a lawyer contend the legality of incarcerating the Inmate. You have to show not only that you have legal authority to incarcerate the guy, you also have to show that you had that authority &lt;em&gt;continuously&lt;/em&gt; throughout the incarceration period.&lt;/p&gt; &lt;p&gt;A typical case where there is a problem is shown below:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;27 June 2011 20:52 – Arrest by Sargent Azulay for car vandalizing.  &lt;li&gt;29 June 2011 09:15 – Detention, 8 days by Judge Judy  &lt;li&gt;5&amp;nbsp;&amp;nbsp; July 2011 – Remanded in Custody by Judge Thachil Oti  &lt;li&gt;14 Aug 2011 – Sentenced, 3 months by Judge Koev Li  &lt;li&gt;27 Sep 2011 – Released at end of sentence&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Do you see the problem? You probably don’t, but for me, it &lt;em&gt;shouts. &lt;/em&gt;The issue is that an Arrest is only valid for 24 hours. Because of the gap in the incarceration warrants, a lawyer can usually get an Inmate out.&lt;/p&gt; &lt;p&gt;That means that part of what the system has to do is to be able to say not only what the current state, but what was the state at any given point in time. Those are usually called Temporal Systems, or Append Only systems, since you are not allowed to make modifications existing data, only create new data.&lt;/p&gt; &lt;p&gt;They also tend to be quite hard to work with, but this is still isn’t a post about the technical stuff, so we will let it go until we get to the good parts.&lt;/p&gt;</description><link>https://ayende.com/blog/50177/macto-non-functional-concerns-you-are-a-legal-system?Key=83ed5c61-e40a-44ad-b388-4258f7a2b30e</link><guid>https://ayende.com/blog/50177/macto-non-functional-concerns-you-are-a-legal-system?Key=83ed5c61-e40a-44ad-b388-4258f7a2b30e</guid><pubDate>Mon, 01 Aug 2011 09:00:00 GMT</pubDate></item></channel></rss>