Thursday, June 13, 2024

Dirty Writes

If there are two people who may edit the same data concurrently, as explained to me when I first started working, there is a serious problem. Someone way back then called it the dirty write problem.

Bob opens up the data and starts to edit. But then he goes to lunch.

During lunchtime, Alice opens up the same data, edits it, then saves it.

After lunch, Bob returns, makes a couple more changes, and then saves his work.

Bob's write will obliterate Alice’s changes. Alice did not know that Bob was also working on the data. Bob did not know that Alice had changed the data.

This problem exists in far too many GUIs to count. Way back people would actually put code in to solve it, but these days that is now considered too complicated. Too long, didn’t code. Alice will just have to remember to check later to see if her changes actually did or did not persist. Lucky Alice. Bob should probably check all of the time too. Maybe they should both write down their changes on paper first...

One way to solve this is to have Bob lock the file for editing. Alice will find out at lunchtime that she cannot edit, but of course, if her changes are urgent it will be a big problem, Bob might be having a very long lunch. Alice will be upset.

Another way to solve the problem is when Bob starts to make his post-lunch edits, a warning pops up saying the underlying data has changed. It would give Bob a screen to deal with it. It’s a bit tricky since Bob already made changes, any merge tool would be 3 way at that point. The original, Bob’s version, and Alice’s version. This might hurt Bob’s brain, and it isn’t the easiest stuff to code either.

A variation on the above is to just err out and lose Bob’s changes. Bob will be upset, it was a long lunch so now he can’t remember what he did earlier.

In that sense, locking Alice out, but giving her some way to just create a second copy seems better. But then you also need to add in some way to reconcile the two copies after lunch, so we are back to a diff screen again.

Because it is complicated and there are no simple solutions, it is ignored. Most systems are optimistic assuming that overlapping edits don’t occur on shared data. They do nothing about it. And if work is lost, most people will forget about it or at least not exactly remember the circumstances, so no valid bug reports.

Occasionally I will run across a rare programmer who will realize that this is a problem. But then I usually have to explain that because we are working with a shoestring budget, it is best if they just look away. Software, it seems, is increasingly about looking away. Why solve a problem if you can pretend you didn’t see it?

Thursday, June 6, 2024

Data Modelling

The strength and utility of any software system is the data that it persists.

Persisting junk data is just wasting resources and making it harder to utilize any good data you have collected.

Storing partial information is also bad. If you should have collected more data, but didn’t, it can be difficult or impossible to go back and fix it. Any sort of attempt to fake it will just cause more problems.

All data is anchored in the real world, not just the digital one. That might not seem generally true, for example, with log files. But those log entries come from running on physical hardware somewhere and are tied to physical clocks. While they are data about software running in the digital realm, the act of running itself is physical and always requires hardware, thus the anchor.

All data has a form of uniqueness. For example, users in a system mostly match people in reality. When that isn’t true, it is a system account of some type, but those are unique too, and usually have one or more owners.

For temporal data, it is associated with a specific time. If the time bucket isn’t granular enough, the uniqueness could be improperly lost. That is an implementation bug, not an attribute of the data.

For geographical data, it has a place associated with it, and often a time range as well.

Events are temporal; inventory is geographical. History is temporal. We’re seeing a pattern. Data is always anchored, therefore it has some type of uniqueness. If it didn’t it would at least have an order or membership somewhere.

Because data is unique we can always key it. The key can be composite or generated, there can be different types of unique keys for the same data, which is often common when cross-referencing data between systems. Mostly, for most systems, to get reasonable behavior we need keys so we can build indices. There are exceptions, but the default is to figure out exactly what makes the data unique.

Data always has a structure. Composite data travels together, it does not make sense on its own. Some data is in a list, or if the order is unknown, a set.

Hierarchical data is structured as a tree. If subparts are not duplicated but cross-linked it is a directed acyclic graph (dag). If it is more indescribably linked it is a graph, or possibly a hypergraph.

If data has a structure you cannot ignore it. Flattening a graph down to a list for example will lose valuable information about the data. You have to collect and store the data in the same structures as it exists.

All datum have a name. Sometimes it is not well known, sometimes it is very generalized. All data should be given a self-describing name. It should never be misnamed, but occasionally we can skip the name as it is inferred.

Understanding the name of a datum is part of understanding the data. The two go hand in hand. If you cannot name the parts, you do not understand the whole.

If you don't understand the data, the likelihood that you will handle it incorrectly is extremely high. Data is rarely intuitive, so assumptions are usually wrong. You don’t understand a domain problem until you at least understand all of the data that it touches. You cannot solve a problem for people if you don’t understand the problem itself. The solution will not cover the problem correctly.

There are many forms of derived data. Some derivations are the same information just in a different form. Some are composites. Some are summaries of the data along different axes. An average for some numbers is a summary. You can get to the average from the numbers, just redo the calculation, but you cannot go the other way. There are infinitely many sets of numbers that would give the same average.

Technically, derived data can be unique. You can have the composite key for all of the attributes of the underlying data that you are combining to get the value. Realistically we don’t do that very often. It’s often cheaper and safer to just regenerate it as needed.

Most data that is useful is complex. It is a large combination of all sorts of intertwined other data structures. As we present it in different ways it helps people make better decisions. It has recursively diverse sub-structures, so it might be a list of trees of graphs of lists, for example. From that perspective, it is too complex for most people to grapple with, but we can adequately work through each of the subparts on their own and then recombine them effectively.

Sometimes capturing all of the available data for something is just too large. We ignore some dimensions or attributes and only capture parts of the data relative to a given context. That is common, but for any given piece of data within that context, we still don’t want it to be partial which is junk. A classic example is to capture a graph of roads between cities without capturing it as a geological database. We dropped the coordinate information, but we still have captured enough of it to properly identify the cites, so later, if required, we can reconnect the two different perspectives. Thus you may not want or need to capture everything, but you still have to be careful about which aspects you don’t capture, which means you still need to understand them.

Data modeling then is two very different things. First, you are setting up structures to hold the data, but you are also putting in constraints to restrict what you hold. You have to understand what you need to capture as well as what you need to avoid accidentally capturing. What you cannot store is as important as what you can store. A classic example is an organization where people can report to different bosses, at the same time. Shoving that into a tree will not work, it needs to be a dag. You would not want that in a graph, it would allow for cycles. If you need to know about who is reporting to whom, you need to capture it correctly. Getting it wrong is misleading the users which is very bad.

Limits of understanding and time constraints are often used as excuses for not spending time to properly model the data, but most difficult bugs and project delays come directly from not properly modeling the data. Data anchors all of the code, so if its representations are messed up, any code built on top is suspect and often a huge waste of time. Why avoid understanding the data only to rewrite the code over and over again? It’s obviously slower.

There is a lot more to say about modeling. It is time-consuming and pedantic, but it is the foundation of all software systems. There is a lot to understand, but skipping it is usually a disaster. Do it correctly and the code is fairly straightforward to write. Do it poorly and the hacks quickly explode into painful complexity that always spirals out of control.

Thursday, May 30, 2024

Identitynet

It’s a simple idea.
 
Anywhere you go in this world, you can prove that you have some attribute. But at the very same time, absolutely all other information about you remains private.

The inquirer gets nothing but an opaque token. Its existence validates that they did check for that attribute and it was successful at that time, nothing else. It would be anonymous, they might link it to some other information they have, but that is up to them.

A check would be in two stages: request and approve. You will see the request and then be able to approve or decline it.

To get around access issues, most people would have one or more delegates. Their delegates could approve or decline on their behalf.

The incoming request would always have the identity of the requester. These would be validated, so trustworthy.

If you were the delegate of someone who got arrested in a foreign country, you would see which officials were making requests about their attributes and be able to accept or deny them. The person arrested might not have access to technology.

Requests would come from an individual or a person on behalf of some organization. In the case of lower-level employees, the requestor would be anonymized you would only see the organization, but it is still trackable and accurate. If there were an issue with that employee, the organization would be able to see who they were, but only in some sort of legal case could they be forced to reveal them. Still, you would have proof that a duly appointed person for that organization did receive confirmation.

You could have lots of different delegates for different attributes. In some cases like citizenship, your attribute would just wrap a token that your country has accepted you as their citizen. You would essentially pass that along.

Access to this system and its information would be available everywhere around the world. It could not be blocked or interfered with by territorial governments.

You can set whatever attributes you want, but getting official ones is a two or more hops to process. You might want to be able to prove that you are the owner of funds in a bank account somewhere. But more likely you would just want to approve a transfer of funds to someone else, while the source account remains anonymous. A token would act as a receipt and a verification that the source funds exist and have been allocated for that transfer. The actual transfer would take place outside, between institutions, and settled at their convenience. That type of token would have a best-before date.

To get all of this to work, you need a globally accessible protocol that can verify the correctness of the tokens it is issuing. The tokens would be secure. You can not tamper with them or fake them. It needs to be fully distributed to avoid being compromised by any individuals, organizations, or governments. As long as both parties can tap into the Internet, the request and approval mechanics will function.

There would be legal remedies for the issuers or holders of these tokens to have to reveal them at times. A token might be evidence in a criminal or civil case for example. If someone requested one of your tokens from the holder, it would be issued as a token itself and you would receive a token about who they are. So, you would know immediately that that person checked your earlier token. You could turn this off as needed.

The tokens themselves would be quite large, but as they are also formal receipts for tracking one half of the request, they are storable and searchable. Declined requests would occupy no space on either side. To prevent DoS attacks, there would be an auto decline that could be turned on for a while.

Some non-formal requests would also be auto-declined. A stranger asking for your name or email, for example. Someone could not scoop these up in a public place.

For social media, the returned tokens could be anonymized. So you could post, without an account, and only legal actions could be used to find out who you are. But you could also issue tokens that publically identify that your post is associated with your account on their site. Both would work, and the social media site is not in control of what is happening.

There would need to be some small type of fee established for using these tokens, mostly to prevent misuse. There could be some way of making it discounted for some people while charging others a fair rate. Likely requests for discounted services would bounce the discount to a different party for approval. You might get your government or a charity to authorize your reduced token rates for example. This would level the playing field for usage.

In that way, tokens would be stacked. One token might link a whole chain of other tokens together to prove a complex attribute, but to reveal all of it in its full detail would require legal remedies against each party in the chain. This would allow eventual transparency, but in a way that could not be abused. You would know who is tracing the token.

Someone could get a social media site to reveal some tokens. Those would link back to an identity provider or government. Going there might have another level of indirection. It might take some time to get to the end of the chain, but the chain is finite, so it would be possible.

All the attributes about you that you might need to share in your life would be tokens in this way. You would have a one-stop location for identifying just the things you want others to know about yourself. You would know what you revealed and to whom.

As all tokens are time-related, you could change those attributes as you need to. So, the trail would be reasonable, you used to prefer to be called Bill, but now it is William. You used to live in the suburbs, but now you reside downtown. The tokens would reflect this, and the dates attached to them would let the holders know both when they are stale and when they should be legally deleted.

This would make a lot of things in life easier, yet provide some protection against the bad stuff.