avatarPete Williams

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3937

Abstract

represent the state changes of the bank account. Each event contains a timestamp, the type of event (deposit, withdrawal, interest accrual), and the amount of the change. To reconstruct the current state of the account, the event stream is replayed, and the cumulative effect of the events is calculated.</p><p id="5b20"><b>Example Events </b>Here are some examples of events that might occur in a bank account:</p><ul><li><b>DepositMadeEvent(accountID, amount, timestamp)</b></li><li><b>WithdrawalMadeEvent(accountID, amount, timestamp)</b></li><li><b>InterestAccruedEvent(accountID, amount, timestamp)</b></li></ul><p id="846d"><b>Reconstructing the Current State </b>To reconstruct the current balance of an account, the event stream is replayed from the beginning. For each event, the corresponding amount is added or subtracted from the current balance. For example, if the event stream contains the following events:</p><div id="64a6"><pre><span class="hljs-built_in">DepositMadeEvent</span>(<span class="hljs-number">12345</span>, <span class="hljs-number">100.00</span>, <span class="hljs-number">2023</span>-<span class="hljs-number">10</span>-<span class="hljs-number">04</span>T12:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>Z) <span class="hljs-built_in">WithdrawalMadeEvent</span>(<span class="hljs-number">12345</span>, <span class="hljs-number">50.00</span>, <span class="hljs-number">2023</span>-<span class="hljs-number">10</span>-<span class="hljs-number">05</span>T10:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>Z) <span class="hljs-built_in">InterestAccruedEvent</span>(<span class="hljs-number">12345</span>, <span class="hljs-number">0.50</span>, <span class="hljs-number">2023</span>-<span class="hljs-number">10</span>-<span class="hljs-number">06</span>T00:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>Z)</pre></div><p id="384f">The current balance of account 12345 would be 149.50.</p><h2 id="9bba">Event Sourcing Key Concepts:</h2><blockquote id="bdf0"><p><b><i>Events</i></b><i> Events are the fundamental building blocks of event sourcing. They represent atomic state changes that occur within a system. Each event encapsulates the details of a specific change, such as a deposit made to an account or a product added to a cart.</i></p></blockquote><blockquote id="e74f"><p><b><i>Event Store</i></b><i> The event store serves as the central repository for events. It persistently stores events in an append-only manner, ensuring the integrity and immutability of the event stream. This chronological record of events provides a comprehensive audit trail of system state changes.</i></p></blockquote><blockquote id="6323"><p><b><i>Event Stream</i></b><i> An event stream is an ordered sequence of events for a particular entity or process. It represents the complete history of changes for that entity, allowing for reconstruction of the system state at any point in time. The chronological ordering of events is crucial for understanding the causal relationships between changes.</i></p></blockquote><h1 id="4081">Architecting for Event Sourcing</h1><p id="b356">In systems utilizing event sourcing, a key difference lies in how data is stored. Unlike traditional relational databases that emphasize the current state of data, event sourcing prioritizes preserving the sequence of events causing state changes. This shift in data management requires a carefully structured architecture to handle both data manipulation and retrieval effectively. Consequently, an event-sourced system neatly divides into two distinct components — <b>command </b>and <b>query</b>.</p><figure id="00dd"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1MH4-bsYG_TNpNn-_HIIww.png"><figcaption><b>Event Sourcing System</b></figcaption></figure><p id="bc30">The <b>command </b>side manages user interactions, translating them into e

Options

vents that indicate intended changes to the system’s state. As the data entry point, it rigorously validates incoming commands before creating and preserving events. Validated events are then stored in the event store, ensuring a secure and unchangeable system record.</p><p id="93a8">On the other hand, the <b>query </b>side exclusively retrieves and presents user data. Focused on constructing view models tailored to the client’s needs, it extracts relevant information from the event stream. This process reconstructs the system’s current state using the chronological sequence of events. Additionally, the query side can notify the client of new events for real-time updates to the user interface.</p><p id="6148"><b>Event Store </b>At the heart of event sourcing lies the event store, a specialized database designed to persistently store events in an append-only manner. This immutable repository serves as the system’s historical backbone, safeguarding the chronological sequence of events that have transpired. The event store’s primary responsibilities include:</p><ul><li><b>Event Persistence</b>: Ensures the durability and integrity of events by storing them in a tamper-proof manner.</li><li><b>Event Ordering</b>: Maintains the chronological order of events, preserving the causal relationships between them.</li><li><b>Event Retrieval</b>: Provides efficient access to events for processing, analysis, or replaying to reconstruct system state.</li></ul><p id="1369"><b>Materialized Views </b>Materialized views, also known as read models, are derived representations of the current state of the system, constructed and maintained by consuming events from the event store. They offer optimized data access for read-heavy operations, enabling efficient retrieval of frequently queried information without the need to replay the entire event stream.</p><p id="aa28">CQRS (Command/Query Responsibility Segregation), with its separation of command and query responsibilities, plays a crucial role in utilizing materialized views effectively. The query side can independently manage and update materialized views based on incoming events, ensuring that the current state of the system is always readily accessible for read operations.</p><h1 id="0fa5">Event Sourcing in Action</h1><p id="b1ea"><b>Event sourcing and CQRS</b> have gained traction in various domains due to their ability to address the challenges of modern distributed systems. Here are a few examples:</p><ul><li><b>Financial Transactions</b> Event sourcing is widely used in financial systems to record and audit transactions, ensuring transparency and traceability.</li><li><b>E-commerce Platforms </b>Event sourcing enables e-commerce platforms to capture user interactions, order history, and product changes, facilitating real-time data analysis and personalization.</li><li><b>Social Media Networks</b> Event sourcing powers social media platforms to handle the vast volume of user activity, providing a scalable and auditable record of interactions.</li></ul><h1 id="57b6">Final Thoughts</h1><p id="f6e0">Event sourcing isn’t just a trend; it’s a game-changer. It gives developers the power to build systems that don’t just handle challenges but excel in resilience and scalability. Imagine a system that keeps a perfect historical record, gracefully deals with hiccups, and smoothly adapts to changes without missing a beat. That’s what Event Sourcing brings to the table. As the need for robust and scalable systems keeps growing, Event Sourcing is becoming the go-to, making its mark as a must-have in the modern software toolkit.</p><p id="f78b"><b>Until our next adventure, stay connected, stay reliable, and keep rocking the digital world! 🚀🌐💻</b></p><p id="1e51">👏 Feel free to give it a friendly round of <b>applause </b>and hit that ‘<b>Follow</b>’ button for more engaging content. Your support truly means the world!</p></article></body>

Photo by Ketut Subiyanto from Pexels

How to be Less Available and Reclaim Your Life

Your phone should be a tool, not a portal to personal hell

“I just feel like I need a break from my life. Every day, my phone doesn’t stop ringing. The other day when I was driving home, I was on the phone the entire time. I just need to be able to take like, a year off to get my life together.”

We’re always told that our network is everything, but what happens when it gets too much, to the point that it’s a liability instead of an asset? Being the introverted type who is ambitious in both my job and outside activities, hearing the above from a friend of mine was a totally foreign concept. Apart from the fact that I have a very small circle of close friends, I’m not one to be available all the time. If I’m busy with something and I get a phone call, I’ll let it go through to voicemail. They can wait.

The extroverted types don’t seem to be able to do that. I’ll be over at my parents for a family dinner every once in a while, and the phone will ring. Immediately my mum will jump up to get it. Why? They know they’re calling at the time people have dinner (which I consider a social faux pas, bordering on rude), your family is here with you and if it’s really an emergency, they’ll call back. What’s the rush?

Considering this phenomenon, it got me thinking, what advice will I give to my friend who feels this constant sense of overload and obligation, who just wants some free time to himself? In line with how I coach athletes, the last thing I’m going to suggest to him is some kind of radical change. Apart from the fact that he likely won’t be able to follow through, it will probably cause him issues with his network of friends and family.

With that in mind, here are some suggestions to the extroverts overwhelmed by obligations, from an introvert who steers clear of them.

Rule 1: don’t tell anyone that you’re doing any of this

Telling people invites conflict and issues where there don’t need to be any. All of these tips are subtle enough that people won’t really notice, leaving you with a sense of relief that getting your freedom back doesn’t mean arguments. The essence of what we’re trying to do is to simply make you less available.

The problem with being an available person who always picks up the phone is that people are always calling you! It doesn’t matter if it’s a life or death matter or something that’s completely unimportant, their first instinct is to pick up the phone, which inevitably leads to you losing time in unnecessary conversation.

It’s like that old saying “if you need something done, give it to a busy person.”

If you always pick up the phone anytime it rings, people are just going to keep calling you.

Turn your phone off for an hour each day

Even half an hour if that’s all you can bring yourself to begin with. This hour can be whenever you most need it to be — whether it’s your commute home, dinner time, after dinner, whenever. That time when you really just don’t want to talk to anyone. Turning it off means that you’re not going to be tempted to look at messages, or see who might be calling you, or getting anxious over how many voicemails you might be getting. Turn it off completely, and revel in the freedom. If anyone asks, you can make a number of excuses:

  • I just needed an hour off, it’s been a stressful day
  • I had an appointment and I couldn’t take calls
  • Was working on something and needed no distractions
  • I’ve been on a call (the best one, because it’s impossible to distinguish between someone’s phone being off and them being tied up on a call)

Turn off your voicemail

Because it’s really no use turning off your phone if when you turn it back on, you have to wade through a dozen voicemails. That’s just going to make your hour of no phone time stressful as hell, which is totally counterproductive. A work phone is obviously a different story, but on your personal phone, voicemail is an archaic and redundant function when people can just text you. The great thing about turning voicemail off is that if it’s really important, people will send you a text anyway.

Don’t return calls unless you need to

Someone called you during your hour of phone off time and didn’t leave a text? Don’t call them back, or at least wait until you feel like doing it, regardless of whether that feels like a few hours or a few days. If it was that important, they would have said something. If you do leave it and they call again in a few days asking why you didn’t call them back, tell them they didn’t leave a text so you assumed it wasn’t important. That’s going to filter out the “I just called to tell / ask you x” vs the people who really need to get a hold of you. This also means that people will start leaving you text messages more often, which can be responded to at your leisure and take less than a minute of your life.

Turn off notifications on messenger

That little ping is quite the nuisance, and it’s designed that way. It’s designed to make your brain want to check it as soon as you hear that sound go off. Turn it off! That way, you’re only looking at your messages when you want to, and you’re no longer a slave to the attention engineers at Facebook.

Remember, the world isn’t going to end because you don’t pick up the phone

If you’re a highly available extrovert, I bet your stomach leaped into your throat at the thought of doing a couple of those. You likely panicked at the thought of what might happen if you turn your phone and voicemail off — all the things that could happen that you might miss! People might get annoyed at you!

Trust me, it’ll be far less dramatic than that. Seriously, you can turn your phone off for an hour, the world isn’t going to end. People will go back to whatever they were doing before they picked up the phone to call you. If it wasn’t important, they’ll probably just forget about it entirely. If it is, they’ll call back.

Seriously, just give it a shot, because making yourself so available to others that it’s turning your life into an exhausted state of being isn’t any way to live.

Most importantly, keep in mind that your phone is meant to be a tool - not a slave master holding you in its thrall. Take back control, even if it starts with just half an hour a day. You can build up from there to the point you feel you’ve reached a nice equilibrium.

Related:

Productivity
Business
Startup
Life
Relationships
Recommended from ReadMedium