Events, The Modern Object Orientation

Talk 30 min

John Bywater
Events, The Modern Object Orientation

Transcript

Read transcript

thank you can everybody hear me okay good so begin I'm jumping water and this talk is called events the modern objects orientation and it's a bit of a new topic for me so please bear with me if it seems a bit strange in classical object-oriented programming we have been modeling the objects that we see in the world such as people organizations tables chairs cats dogs we have the Hazar and is a relation we have crud and our M's we have problems with that called the object-relational impedance mismatch is a huge Wikipedia page all about that and some been described as the Vietnam of computer science because you just go there and die and because of this it's actually difficult to make reliable disputed systems and a lot of details there that I just don't have time to go into but we just have to accept that as the starting point for this talk over the past 10 years there's been shift to modeling events and we modeled what happens in the domain such as a person was born an organization was established tables scratched chair was moved cat died dog barked modeling events led to something called event sourcing how many people have heard of event sourcing great so eventuosity is an architectural pattern in which the state of the objects we see is determined by a sequence of events and the question that I had was how after working with this refuse had general is it and can you do event sourcing only in some places or is it a general approach there was an article for quite a few years almost at the top of the Google search results which said that event sourcing a whole system is an anti-pattern so you know if you want some discouragement and there it is and I didn't know if mmm if it was something that would go wrong for some reason didn't know why wouldn't work in general and I just kind of accepted that there would be some limitation to it and I would get burnt by if I just carry on regardless and hmm so the question is can all domains be investigated by asking what happens and the flip side of that is if we consider only the events what do we overlook what evades our attention if we only look at the event so I wondered what is the status of an event in the real world and how two events relate to the actual entities of classical objects orientation it turns out this is a massive question in metaphysics going all the way back to Aristotle Plato before and many other sins in the classical conception what we're expected to believe is that to get a dog for example you start with the eternal dog form and then instantiate a real dog by having substance and have filled your empty form it's not a from the Greeks it's an ancient or classical idea it's not a concept that was invented in the modern era it's an idea that came before notions of growth and development for example in biology it's an idea that came before the Industrial Revolution its philosophy before Descartes Spinoza Newton liveness Locke Berkeley Hume Kant Hegel bugs and it's something before the notion in quantum physics that particles are just events in the quantum field it's something that came way before modern information technology before we had computers and software and the trouble with software is that there's no place to hide if it doesn't work it just doesn't work and that's what we discovered with this classically conceived objects orientation especially when it comes to distributed systems which for in consequence had to be really hard so how can we update our concept so they are adequate for the modern world of science and technology in which we live it turns out that somebody ordered a very good job in this area and that person was called Alfred North Whitehead the picture of him white Whitehead was born in 1861 he died in 1947 and we said he was a genial sort of person he's a professor of mathematics at Cambridge and later professor of philosophy at Harvard there was a very famous book brink appear Mathematica and which is whiteheads most famous mathematical work he was co-written with his former student Bertrand Russell and it's considered to be one of the 20th century's most important works in mathematics placed 23rd in a list of the top 100 english-language non-fiction books of the 20th century so he was already quite famous because of that in his later life he moved to Harvard and started on his philosophical work of which process and reality is his masterpiece and Alan Turing for example read whitehead when chewing was at school and we know this from some records in the library that some records of his of the books that each account in the library and produce and reality was published in 1929 when Whitehead was 68 years old and there were eight contemporary book reviews of the 1929 edition and one person said the situation can be made clearer by saying bluntly that this work surpasses Aristotle's metaphysics and can't critique of pure reason for intrinsic importance then naturally not as yet for historical standing or influence a guy called demon wrote in his 1930 review not many people will read whiteheads recent book in this generation and not many will read it in any generation but its influence will radiate through concentric circles of popularization until the common man will think and work in the light of it not knowing whence the light came after a few decades of discussion and analysis one will be able to understand its more readily than can be done now so I'm going to trace some of the ways in which that light has illuminated our work especially through things like pattern language but firstly whiteheads philosophy is a process philosophy process philosophy is now primarily associated with Alfred North Whitehead the basic idea of process philosophy seems to be that the future doesn't exist the past is dead presidents loss is traced back to a greek called Heraclitus 500 BC who was famous for his insistence and ever-present change as being the fundamental essence of the universe and for saying no one ever steps into the same river twice this is commonly considered to be one of the first digressions into the philosophical concepts of becoming the phrase nothing in the world is constant except change and becoming is attributed to Heraclitus and in the 1920s Whitehead wrote the ancient doctrine that no one crosses the same river twice is extended no thinker thinks twice and to put the matter more generally no subject experiences twice white had was very quotable he really didn't like people just taking quotes out of his book but but it's kind of something - one one thing he said is the safest general characterization of the European philosophical tradition is that it consists of a series of footnotes to Plato so that's perhaps his most famous quotes but this quote about a fish is also quite well known I saw it on a train poster once in the train to Cambridge just you know ideas do not keep something needs to be something needs to be done about them and so let's look at the I the scheme of ideas itself why had called the system of ideas in his book personality of philosophy of organism philosophy of organism is the doctrine that the creative advance of the world is the becoming the perishing and the object immortality objective immortality's of those those things which jointly constitute stubborn facts Whitehead wrote the philosophy of organism is a cell theory of actuality each ultimate unit of fact is a cell complex not analyzable into components with equivalent completeness of actuality the cell can be considered genetically and morphologically and that distinctions taken forward by Christopher Alexander in his in his later work and these are some of the some of the different concepts involved and I'll touch on on those just now firstly creativity Whitehead invented the word creativity we have the word creativity in our language because of Whitehead and his previous word whose creativeness so creativity's without a character of its own in exactly the same sense in which the Aristotelian matter is without a character for its own it is that ultimate notion of the highest generality at the base of actuality it cannot be characterized because all characters are more special than itself and he reaches back to Plato and finds more or less his whole system captured in this snippet this conception of an actual entity in the fluent world is little more than an expansion of a sentence in Plato's Timaeus but that which is conceived by opinion with the help of sensation and without reason is always in the process of becoming and perishing and never really is and for the people verdict monads and Whitehead said that his system is a monad ology but the difference between his monads and Leibniz moment is that whiteheads moments don't change so the big question is what are the actual entities the classical answer is that the actual entities are instances of substance quality categories and so the the brown dog and so on if you can and you can in the intense model of real world with objects and you can see it in the attempts to model the real world with objects such as cats and dogs and people and organizations and tables and chairs whiteheads move was to assert that the classical idea suffers from the fallacy of misplaced concreteness and that the actual entities are occasions of experience so he said the current counts of perception of a stronghold of modern metaphysical difficulties they have their origin in the same misunderstanding which led to the Incubus of the substance quality categories the Greeks looks to stone and perceived that it was grey the Greeks were ignorant of modern physics but modern philosophers discuss perception in terms of categories derived from the Greeks and so does classical object-oriented programming whiteheads big claim is that the actual entities are occasions of experience and he calls these creatures Whitehead said there is no going behind actual occasions to find something more real the named event was given to a nexus or multiplicity or network of such occasions with the simplest event having only one occasion so building up the conception here actual entities involve each other by reason of their prehension of each other there are thus real individual facts of the togetherness of actual entities which are real individual and particular so an a society of events is when the elements of Nexus are united by a defining characteristic that is common to all of them or that they have all inherited from one another or acquired by a common process and some societies have what Y had calls personal order which and which is where the events are ordered as a series of events and this is remarkably close to the notion of event sourced aggregates then we have the enduring physical objects the real actual things we encounter in the world are all societies Whitehead also calls them enduring physical objects building is an enduring physical object for that matter so am i myself a society also can have many strands of personal order the name Whitehead uses for this is corpuscular society a collection of entities each with a personal order for example the individual histories of all the people at the conference or the taste buds on your tongue this is remarkably similar to a collection of event sourced aggregates in an event sourced application there are also these things he calls eternal objects which is a kind of update of plato's eternal forms so tonal objects are forms of definiteness pure potentials realized in a particular actual entity contributing to its definiteness eternal objects tell no tales of actual occasions there are no novel eternal objects Whitehead defines eternal objects as follows any entity whose conceptual recognition does not involve a necessary reference to any definite actual entities of the temporal world is called an eternal objects this means that eternal objects includes sensory qualities like colors and blueness or greenness and tactile sensations softness or roughness conceptual abstractions like shapes a helix a dodecahedron and numbers 7 or the square root of -2 moral qualities like bravery or cowardice physical fundamentals like gravitational attraction or electric charge and much more besides an eternal object can also be a determinate way in which a feeling can feel an emotion or an intensity or an ad version or an aversion or a pleasure or pain all events have feelings but not all have higher grades have the high grade of feeling that we might refer to as conscious intellectuality however intelligent you might be you can't be conscious of everything that happens to you and Whitehead gave a definition of function which is to contribute determination to events as Ward Cunningham wrote in episodes programming is the act of deciding now or what happen in the future in general since events are self creating this is remarkably similar to the notion of herding cats which is a phrase I used to hear quite a lot and software developers reflects and in complete control managers have in any creative industry so we have also this notion of chaos and non social Nexus is what answers to the notion of of chaos so assistant frameworks like kin even have this domain of chaos that you try to move away from but actually it's more complicated than perhaps simpler and so we have this this diagram Whitehead set of events are four stages you can see the four stages in this diagram you can use the diagram to model anything by telling the different bits of text and questions the first stage is datum the objective content of the experience facts from the settled world objectification z' and subjective form resulting from processes of appropriation which white had calls feeling the second stage process solves the question of what the event is to be it finds a settlement in its datum the third stage satisfaction forms a subjective unity or harmony and harmony there is exactly the same thing that Christopher Alexander uses in his in his pattern language it's just exactly the same the final satisfaction is the individual unity of the event that makes it what it is the fourth fourth stage is a decision which constitutes the events actuality as a stubborn fact which cannot be evaded Whitehead wrote thus the datum is the decision received and the decision stage is a decision transmitted and in between these two our process and satisfaction the subjective aim and it's a proposition and the function of a proposition is to your feeling and the subjects of the event is the event itself to briefly look at the episode which gave us process and reality and I've arranged this slide following whiteheads four stages of an event first the Dayton white had read the Greeks in Greek when he was a boy we can read in his book process and reality that white had found the considerations of the Greeks and the ideas of Plato Aristotle Descartes Kant Hume Newton's on a next bag although he found many things he liked to which he says here occurred he felt there was an overall incoherence and individually their ideas mistaken in various ways and in consequence rather laboured wanted wrote an endeavor has been made to point out the exact points of agreement and of disagreement he appropriates their work he makes his own propositions reworking things whilst giving lectures until he reaches a satisfaction and his book is printed all these notes and manuscripts were destroyed when he died on his wishes so all we've got really is this book that's that was whiteheads process and language Whitehead was enormous the influential for Papa Christopher Alexander I've checked this with his friends he really was influenced quite a lot by him and you can see it in in his book the timeless way of building and you can also see it when he refers to Brian Goodwin's work which was directly influenced by white hand and this quote was pointed out to me by James Coplin I was trying to find some quotes before there's quite a lot of things in there but I think this is probably the best one where Alexander says and finally of course I want to paint a picture which allows me to understand the patterns of events which keep on happening in the thing whose structure I seek in other words I hope to find a picture or a structure which will in some rather obvious and simple sense account for the out which properties for the pattern of events of a thing which I'm studying and it's not really apparent really when you look at pattern language to begin with that he's he's really talking about patterns of events there's a it's not necessarily so clear that that's what's happening but that's really when it's coming from and in software development some Chris Flags Andrews enormous influential for Ward Cunningham inventor of wiki wiki he also authored a number of patent languages for example episodes published in 1995 and episodes describes a method of software development in this pattern language everything is an event the really remarkable facts about this text and the reason I included this in this talk is the close resemblance what Whitehead said about events in particular the four stages and events and the notion of becoming quite visible here so what coming in the introduction to his episodes you're gonna pre cursed extreme programming we are particularly interested in the sequence of mental states that lead to important decisions we call a sequence an episode an episode builds towards a climax where the decision is made before the decision we find facts share opinions build concentration and generally prepare for an event that cannot be known in advance after the climax the decision is known but the episode continues in the tail of an episode we act on our decision promulgates it follow it through to its consequences we also leave a trace of the episode behind in its products it is from this trace we must often pick up the pieces of thought in some future episode you can see there's enough facts through some kind of process to another facts and then you're just working with a settled world of facts that you have and then the development repeats and another thing scrum people heard of scrum and is defined with an artifact which results and the actual occasions of the scrum events or scrum prescribes for formal events for inspection adaption as described in this grammar section sprint planning the daily scrum sprint review and sprint and retrospective you can obviously read more about scrum I just think it's interesting that there's there's there's aspects to software development which aren't really conceived as events like how the team comes together however how you know the the occasion of software Davone is selfish constituted seems not so well that's so well worked as an event anyway so distributed systems as a multiplicity of process events in which domain events may be generated can we be more definite about reliability in the distributed system that processes domain events by being more definitive about what actually happens and that processing if we want to make a system that is reliable what can we actually rely on is it possible to define the process events in terms only in terms of only things that we can actually rely on so what can we rely on well we've got acid database transactions which are 100% reliable and the other thing that's 100% reliable is its counting and it turns out that we can build distributed systems based on just those two things and so just to step through this firstly unreliable propagation this is a kind of basic the basic approach that we start with really and we we execute a command and then notifications the domain events are sent over a message but us like rabbitmq us and this is unreliable because if the domain events are written first then the notification might not be sent and if the notification is sent first and the domain events might not be written even if the domain events are written atomically and the view updated atomically it remains the notification isn't atomic with the domain events and the consumption of the notification isn't atomic with the updating of the view so there's lots of ways in which you can go wrong if you imagine your system just crashing any points in time if it just happens to go wrong before in between one thing happening and the other thing happening that you're expecting both things to happen then it's gonna go wrong and you're gonna see that somehow in the state of the application so if you want to do reliable propagation that the notifications and domain events need to be written atomically and if the view is updated atomically with a tracking record that shows which notification was last processed and we can use counting to sequence and follow the notifications and if processing is resumed using tracking if the thing crashes in your resume if it's resumed using tracking information and propagation and projection of the state of application will be reliable the details about doing this with notification logs and Vaughn vernon in his book implementing domain driven design explains quite well how to do this with notification logs and archived sections of these things and we can take this at least one step further by replacing the view with an event sourced model so now we have into the place that I want to end up if we make if you make the view event source then we were basically projecting the state of one application into the state of another application in this case we have to put three things in the database atomically the tracking information so where you are in the sequencer you're consuming the domain events which is the new state that you're producing by processing that notification and the notifications of those domain events the others may consume and that more or less defines or to process offenses so using only counting and local atomic database transactions so long as the infrastructure allows the process to advance at all the event processing can happen absolutely reliably the new notifications allow the projected state to be propagated to another application in this way such applications can be composed to make reliable distributed systems and such a system is reliable as its atomic database transactions which is 100% well I believe injustice have perfect replication there's no there's no there's no real chance there's a way in which it can go wrong because everything's just tied down so here's that protis event drawn as an event than the same diagram sort of shape as the years whitehead's event with the four stages the subjective aim is perhaps to keep up to date the dates moves more or less the domain event notification the current application state and the application policy itself the process is to apply the application policy whenever there is a new domain event notification the satisfaction is the new domain events that satisfied the application policy and the decision is where the records of the process events actually written into the database or perhaps not depending on infrastructure failure so you can see you're gonna record the whole process event or not and if you don't then when you resume you'll that's the thing you'll do and you're trying to do that until it's done and then you'll move on and and then I tries just fun just to write this as a as a past and I know the text really small I'm not gonna read the whole thing and it probably needs more work but basically it says that by using counting to sequence the domain events of an application and atomic database transactions to record each process event application stage will be entirely unaffected by infrastructure failures and so we can create these protists applications where we factor out the process event functionality and that allows an entire system of applications to be defined independently of infrastructure not just the domain model so in domain different design the the encouragement is to try to make a model that's independent infrastructure and to bind the model to infrastructure at runtime but if you can make a process application can define an assistant where a number of process applications are linked together and you can define the whole thing independently of infrastructure and the infrastructure is only involved in the systems run and that gives you the opportunity to use different runners for different purposes single threaded multi-threaded multi processing running on your cluster so the thing single thirty things really nice for development and then you can deploy and expect to get exactly the same behavior from from a properly distributed system and I just coming to the end I developed a library for event sourcing employees and it was developed over several years from real-world professional projects just gradually refactoring and things that actually worked and the library implements the basic events or some stuff and also the protis event staff allowing you to define a reliable distributed system independently of infrastructure as far as I can tell this is a genuine innovation that hasn't so far been implemented in any other language and I asked Eric Evans about this anomaly this year and he said he hadn't seen it before and also that I'd systemized it really nicely so the idea from the main different design is that if you if you can partition a conceptually cohesive mechanism into a separate lightweight framework particularly watch out for formalisms well-documented categories of algorithms expose the capability of the framework the intention revealing interface now the other elements of the domain can focus on expressing the problem delegating intricacies of solution to the framework so that was the reason why I thought it was justified to make a library and at the time a few years ago the general advice was that events or seems so simple that you just don't need a you don't need a separate library you can just do it fresh every time but it just turns out not really to be true anyway this code is available under MIT under a permissive license Berkeley free course and it's on github my name on that you're on violent events Orson and I'll be running a workshop I think it's at one o'clock I'm introducing this library and I hope some of you will come on that's [Applause]