Event Carried State Transfer: Keep a local cache!

  Рет қаралды 9,737

CodeOpinion

CodeOpinion

Күн бұрын

Пікірлер: 33
@juliaroberts9602
@juliaroberts9602 2 жыл бұрын
I have been trying to access various resources to understand events and your videos are one of the best explanations out there. I also appreciate how you reply to almost all comments. Thank you!!!
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Glad it was helpful! I try to reply to as many as I can assuming I don't miss them. Replies are harder to keep track of though. Sorry If I don't reply to a reply :)
@brettmiller6955
@brettmiller6955 8 ай бұрын
Great video! What I'm struggling with is the best way to for service A to get data from service B, that it might have missed or perhaps wasn't interested in when service B sent out a state change or maybe service A didn't exist at the time service B was publishing state changes. Now service A is interested but service B has no reason to publish state again. Service A could ask service B to publish all its state again but this might publish more than service A needs and would maybe cause other services to consume the state message unnecessarily as well. Anyway, hope that makes sense, maybe you have a video that addresses this :)?
@SnOrfus
@SnOrfus 2 жыл бұрын
If you’re using Kafka and have something like the customerId as the partition key, then you don’t have issues with competing consumers pulling from that stream. You can take it a step further and create a ksqldb query to define the local cache/table and it should get updated automatically (I’m working on a POC of this nowish).
@florianfanderl6674
@florianfanderl6674 2 жыл бұрын
How would you handle the initial load, if you connect to the dependency late and data doesn't get updated regularly?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Most expose an API to backfill data they need.
@muthukumarankothandaraman2371
@muthukumarankothandaraman2371 2 жыл бұрын
For example, most of databases have replication workflows, wherein when new node(s) are added to db cluster, some empty replicas would be allocated on newly added node(s). And there would be a bulk transfer from existing replicas to newly allocated empty replicas. Similar approach can be followed
@krzysztoffrydrych204
@krzysztoffrydrych204 2 жыл бұрын
What do you think about trying not to duplicate the data at all, just some sort of correlation ID and use UI composition to display stuff from various services. I've seen this approach on few conferences and trying to implement this in some side projects. Seems like a very hard thing to achieve but not impossible I guess 🤷
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Yes, doing the UI composition on the frontend. There's also the idea of having the client make a single request and have a BFF (backend for frontend) do the composition there. Ultimately it's going to happen somewhere.
@caspera3193
@caspera3193 Жыл бұрын
​@@CodeOpinion API composition on the frontend is not a solution that is always available. For example, if I have a stock-service and a product-service with millions of records and I want to query red products that are in stock, it is not going to work. The composition would take way too long given that there are millions of resulting product IDs from both sides that have to be retrieved and matched against each other to get the products that the user wants. In this case, duplicating data in a service that is dedicated to searching products would be a viable solution. This approach is scalable and you can also select a database system that is better suited for the job (searching products with complex parameter combinations).
@marcinkossakowski4737
@marcinkossakowski4737 2 жыл бұрын
Hi Derek, what are your thoughts on using this technique for events that need to be aggregated? e.g. some service needs info on payments (total amount) that happened since some time? API call could be used to build initial state, then use events to modify state?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
As mentioned at the later portion of this video, you should have data where you need it. In other words, direct commands to the service that should own the data. Propagating reference data via event carried state transfer can make sense, especially if you want to do some type of view/ui composition. But if you need data in a service for business rules or to perform a command, it should own it.
@Antash_
@Antash_ 2 жыл бұрын
I wonder what are your experiences with the "versioning": do you use timestamps? Counters (if yes, then how they are implemented)? I remember probably from Martin Kleppmann's book that relying on timestamps can be prone to errors, as the clocks on different machines can be set up differently, plus other time-related issues.
@rcts3761
@rcts3761 2 жыл бұрын
An easy way would be to use auto incrementing IDs in a transactional database with the outbox pattern, since you're probably using outbox anyway.
@georgehelyar
@georgehelyar 2 жыл бұрын
I know this was mentioned in the video but you could use FIFO on the broker for this, as long as you're not using competing consumers within the same scope. For example, with Azure Service Bus you can use sessions on a topic to ensure processing is ordered correctly. You can still process e.g. multiple orders (or whatever you choose as your session scope) at the same time, but you can ensure that the consumer is only performing one operation on any given order at a time.
@zeamessaoud
@zeamessaoud 2 жыл бұрын
You can use logical counter, increment it when update and check expected version to update.
@jahedurrahman3181
@jahedurrahman3181 2 жыл бұрын
I like your videos. These are very informative. Question: when service A calls Service B and waits until it times out or gets data back, does this mean Service A is blocked and cannot be used/called by any other process?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
No, not likely blocking other calls, so you're service won't be unavailable.
@codecomposer88
@codecomposer88 2 жыл бұрын
Awesome. Very well explained, thanks!
@CodeOpinion
@CodeOpinion 2 жыл бұрын
You're welcome!
@strandedinthe0737
@strandedinthe0737 2 жыл бұрын
Ok, what can you say about meta information in this context? For example authentication information, or smomething like that. Do I need put it into a message? And how it looks like?
@asbjornu
@asbjornu 2 жыл бұрын
One recommended solution for that is for the event to only emit its name and a URL where the event data can be found. The URL can then be authenticated and authorized as any other HTTP service according to who the client requesting the data is.
@rcts3761
@rcts3761 2 жыл бұрын
@@asbjornu That sounds pretty complicated. You need to take care of saving the event, generating the URL, serving the requests. You couple your consumer to the availability of the producer and you will burden the producer with traffic from the consumers. I would probably encrypt the events and only give the key to authorized consumers.
@asbjornu
@asbjornu 2 жыл бұрын
@@rcts3761 as always, It Depends. In most organizations, the origin service that emits the event will have the API with authorization in place already, so serving the event subscriber does not come at a (huge) cost. The event subscriber needs to place the received event in a queue for processing and ack it once it's successfully processed. That's a smart thing to do regardless of how the event is processed to ensure event ordering, exactly once delivery and other event- and message-related problems you need to deal with in an event-oriented architecture either way. Encryption is another option, but that requires a PKI infrastructure which is also not free.
@pablocom
@pablocom 2 жыл бұрын
Really interesting, thanks for sharing!
@CodeOpinion
@CodeOpinion 2 жыл бұрын
My pleasure!
@baraniecc
@baraniecc Жыл бұрын
Cool video. Let's say we have the pattern in place. Now we want to introduce new service that we want to cache the same data (or subset of it). What's the best way to approach it? Reply all the events? Manual export/import? sync calls?
@CodeOpinion
@CodeOpinion Жыл бұрын
You're comment made me create this video: kzbin.info/www/bejne/iJS5l2CIbLeNmbs
@renz82
@renz82 2 жыл бұрын
How does a delta vs fat work here ?
@CodeOpinion
@CodeOpinion 2 жыл бұрын
So as long as you have some indication of version. The issue most run into with deltas is missing one or not handling it correctly. Now you don't have eventually consistent data, you have inconsistent data.
@mabdullahsari
@mabdullahsari 2 жыл бұрын
04:30 What if the developer is in the EU, like me? 🥲 That's a huge GDPR issue.
@CodeOpinion
@CodeOpinion 2 жыл бұрын
Then you're not likely sharing that type of data via Event Carried State Transfer!
@simonk1844
@simonk1844 Жыл бұрын
I'm also in the EU, and haven't found any problem with this pattern. When a "data owning" component deletes data, it just publishes an appropriate event and all consuming systems then respond by deleting their copy of that data.
Workflow Orchestration for Building Resilient Software Systems
11:57
Wix.com -  5 Event Driven Architecture Pitfalls!
13:36
CodeOpinion
Рет қаралды 12 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 25 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 17 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 4,9 МЛН
Event-Driven Architecture (EDA) vs Request/Response (RR)
12:00
Confluent
Рет қаралды 173 М.
Shared Database between Services? Maybe!
13:51
CodeOpinion
Рет қаралды 24 М.
You want to use Kafka? Or do you really need a Queue?
11:43
CodeOpinion
Рет қаралды 23 М.
Blocking or Non-Blocking API calls?
13:22
CodeOpinion
Рет қаралды 10 М.
Microservices gets it WRONG defining Service Boundaries
10:15
CodeOpinion
Рет қаралды 12 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 101 М.
Should You Use gRPC Instead of REST?
19:11
ArjanCodes
Рет қаралды 18 М.
Message Ordering in Pub/Sub or Queue
11:39
CodeOpinion
Рет қаралды 11 М.
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 25 МЛН