Тёмный
No video :(

Should you Delete or Soft Delete? 

CodeOpinion
Подписаться 86 тыс.
Просмотров 11 тыс.
50% 1

Опубликовано:

 

28 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 83   
@zimcoder
@zimcoder 2 года назад
Sometimes a user requests that all the data be deleted permanently, you can't just make another entry elsewhere that they requested to be deleted and capture data on that event because you will be violating their right to be forgotten. Sometime a delete is just a delete.
@amlyo6722
@amlyo6722 2 года назад
right-to-be-forgotten requests can be incorporated into the design of ledger based systems with appropriate encryption and a forgettable key per customer.
@zimcoder
@zimcoder 2 года назад
@@amlyo6722 that simply means you have just hidden their data and not forgotten it... A sophisticated soft delete
@amlyo6722
@amlyo6722 2 года назад
@@zimcoder If the person who does your backups ever tells you this, it's time to start panicking
@Andrej.
@Andrej. 2 года назад
🤣
@kanadaj3275
@kanadaj3275 2 года назад
@@amlyo6722 I mean, he isn't exactly wrong. Forgetting an encryption key simply means it's "forgotten for the foreseeable future", not actually "forgotten". Someone 10 years from now could obtain a leaked dump of your database and decrypt it using, say, a quantum computer. It's not exactly a clear-cut issue.
@everydreamai
@everydreamai 2 года назад
A lot of your videos hit on a very important topic without actually explicitly getting into it. It's very important to have a competent product owner who can focus on delivering their team with meaningful acceptance criteria for actual business cases instead of things that look like CRUD operations. This is often a challenge with businesses that do a poor job aligning teams with business functionality and not technical considerations.
@CodeOpinion
@CodeOpinion 2 года назад
You got the point of the video!
@TheRicherthanyouguy
@TheRicherthanyouguy 2 года назад
I can 100% support this mind set. I’ve worked in large scale and super small projects and in my experience I’ve started evolving away from a soft delete an instead use some kind of enumeration or status code id usually stored in a database of some sort to define that current status of data. I think a lot of the frustration caused here is generally because these type of thinking does require user interfaces and queries to be a bit smarter than we might like but I’ve found it’s usually worth it.
@sethdodson5475
@sethdodson5475 2 года назад
One notable exception: if your business wants to comply with European privacy laws and receives a request to delete PII for an individual, then deletion truly is in line with a business process.
@ddruganov
@ddruganov 2 года назад
A great example of domain specific language usage!
@grumpydeveloper69
@grumpydeveloper69 2 года назад
Even when from a business standpoint you don't think of hard deletes, regulations like the GDPR and right to be forgotten laws would still requires systems to be able to hard delete. How do you handle such regulatory requirements?
@CodeOpinion
@CodeOpinion 2 года назад
Delete if you need to delete.
@sangmin7648
@sangmin7648 2 года назад
Thanks for the video! Choosing between event sourcing and crud seems to be a difficult job. How should I know when to use which? And later down the line, when I realize that I should’ve gone with the other method, how should I make the change? Changing from event sourcing to crud seems pretty simple, as I already have all the data. But how should I change from crud to event sourcing? Or should I just event source everything to be safe?
@CodeOpinion
@CodeOpinion 2 года назад
It's not about CRUD vs Event Sourcing. You could be recording current state in the way I showed it with a document and having a collection that recorded when they were hired and terminated.
@fabiogusmaoribeiro
@fabiogusmaoribeiro 11 месяцев назад
Expanding on the subject of soft-delete, do you believe that adding "created by", "created at", "updated by", "updated at", "deleted by" and "deleted at" columns to your database is redundant when you can grab that information from the event store?
@CodeOpinion
@CodeOpinion 11 месяцев назад
Depends how those columns are being used, I suspect just for information/query/view purposes. If you're in CRUD mode, then yes. If you're not then you probably don't have those columns but more-so like a CancelledDate, EmploymentTerminatedDate, etc.
@cdnkarasu
@cdnkarasu 9 месяцев назад
Soft delete is useful for adding a versioning mechanism. Also an alternative is to use temporal tables.
@hemslingo7219
@hemslingo7219 10 месяцев назад
Very easy situation to get into. The most annoying repercussion I've come across is having to omit IsDeleted entities throughout the entire application, including navigation properties. If you're selecting from the db at the root entity level, it's very difficult to deal with in a large app.
@Oswee
@Oswee 2 года назад
Nah... you should cover GDPR where users has rights to wipe out their data. So you should wipe out all sensitive marked data. You can't keep it in original form.
@MiningForPies
@MiningForPies 2 года назад
Only if the data is covered by gdpr
@CodeOpinion
@CodeOpinion 2 года назад
Correct. This video has nothing to do with GDPR. There are many ways of handling, one of which is deleting data. If you need to delete data because of GDPR, sure. You could also encrypt data and lose the key. The point of the video is to illustrate to capture business concepts explicitly.
@Oswee
@Oswee 2 года назад
Then i didn't got a message of this video correctly. My point was that there are more than Delete vs Soft delete.
@ColinWhittingham
@ColinWhittingham 2 года назад
In that case could you just anonymize any identifiable fields in existing data (name, address, email etc.)? Would this satisfy GDPR whilst preserving most of the events?
@Oswee
@Oswee 2 года назад
@@ColinWhittingham This is how this is typically done. But you must do the homework to avoid the hunting for data traces.
@chadgregory9037
@chadgregory9037 2 года назад
about 15 minutes of real, actual work.
@CodeOpinion
@CodeOpinion 2 года назад
ha!
@MiningForPies
@MiningForPies 2 года назад
Soft deletes are the bane of my existence. Got a system I’ve inherited where the soft delete flag means something different depending on the entity it’s on. And query/report performance is crap because it’s got to be included in every one
@CodeOpinion
@CodeOpinion 2 года назад
Yup! It's not really "deleted" it has some explicit meaning that is different in a different entity/context but it's implied with isDeleted. Not fun. Make the implicit explicit.
@br3nto
@br3nto Год назад
It would be helpful if you describe what the database schema and database changes would be for the evented version. It’s easy to see how soft delete works because you showed the schema with the IsDeleted column and how/when it is updated. But it’s not clear on what the db schema is and how data is managed in the evented version.
@CodeOpinion
@CodeOpinion Год назад
If your were event sourcing, the individual events define their own schema. All the events for a particular aggregate are persisted in a stream. This video might be helpful if you haven't watched already. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-AUj4M-st3ic.html
@Thorarin
@Thorarin 11 месяцев назад
And then GDPR became a thing for many of us, so we cannot just keep data around indefinitely. Eventually you will have to hard delete if it applies to your business.
@mahmutjomaa6345
@mahmutjomaa6345 2 года назад
So you would add data with more information (i.e. EmployeeTermination and EmployeeHiring) instead of toggling an isDeleted flag because the facts of what happened might be important.
@CodeOpinion
@CodeOpinion 2 года назад
Correct. It's about capturing the business concept (where appropriate).
@MisterNOmercy
@MisterNOmercy 2 года назад
Another interesting topic: does doing a hard delete, cascade delete other data? I believe cascade delete is evil; i think that if you want to delete a user in the code, you need to delete relevant data with code as well That way you do not need delete too much data. And if you dont delete all relevant data, you get an error when deleting the user
@CodeOpinion
@CodeOpinion 2 года назад
It really depends on the context if it's appropriate.
@AaronInCincy
@AaronInCincy 2 года назад
How do you handle mis-keyed data in a task based system? Let's say an employee moved, and you go through the workflow of entering a new address. You click save, the system kicks off an employee moved event and everything is great. Then you noticed you miskeyed their street name. Do you have another employee moved event? They didn't really move twice. Do you have an AddressCorrected event? At that point do you have to support task based AND crud based events for every piece of data?
@CodeOpinion
@CodeOpinion 2 года назад
Task based doesn't imply you're publishing events. It sure helps to do so, but performing a command doesn't mean it has to publish an event.
@rauldeandrade
@rauldeandrade 2 года назад
The employee didn't move twice, but they also didn't move to the first address. I'd rather just create a second move and maybe add a field "reason" for moving where I can say "previous move error" under EmployeeAddedAddress event. Although I'm not against deleting an address, I must confess I'd stress out about the address use dependencies elsewhere. I'm just thinking off the top of my head. I don't really have an implementation example come to mind where I had to address this before
@marna_li
@marna_li Год назад
"Why store all these events and data taking up space?" - Because of auditing. "But I don't need that" - So be it, this is just a concern that might become important to your business later down the road. You need to know that this is a way of thinking about your system. And you don't have to go all in on event sourcing for this either.
@CodeOpinion
@CodeOpinion Год назад
Yes, capturing business intent has many benefits, one being auditing.
@ronifintech9434
@ronifintech9434 5 месяцев назад
Looks like this is a good approach for nosql? how do you implement something like this for SQL?
@FISS007
@FISS007 2 года назад
I totally agree with you. There are even some regulations and laws that forbid data deletion and enforce keeping data history.
@ramonennik2536
@ramonennik2536 2 года назад
That's was the same question I had! For example we do have accounts where all personal data has to be wiped or scrambled when they want to delete their account because of the GDPR. (So the other way around, we must delete the data by law)
@CodeOpinion
@CodeOpinion 2 года назад
The intent of the video is to illustrate that often there are business concepts to capture that soft deleting doesn't provide. Capture business concepts if applicable. If you need to delete data, delete it.
@void_star_void
@void_star_void 2 года назад
What about the right to be forgotten? instances when you ask the company to delete your data
@CodeOpinion
@CodeOpinion 2 года назад
Then delete the data. The point of the video really is to capture business concepts explicitly when traditionally you would think about deleting or soft deleting data.
@roko567
@roko567 2 года назад
Soft deleting user info is illegal in Europe
@FrantisekSidak
@FrantisekSidak 2 года назад
You can anonymize, and if I know, in special cases, you have obligation to keep data anyway (accounting). So the concept still makes sense.
@chengchen9032
@chengchen9032 2 года назад
yean totally agree that events are more informative than crud, but I feel like the storage of events could be challenging. do you have any advice on that? let's say one entity is a row in the sql db, if its crud, no matter how many events happened in the domain, cuuud ends up with d, one row less for the table, however, it would be five events to stored if we do event sourcing.
@CodeOpinion
@CodeOpinion 2 года назад
You don't need to do event sourcing to capture the business concept. As I illustrated with the document example that's recording current state (not event sourcing) I had a collection that recorded the hiring and termination. If you were using tables, you'd probably have table with columns for HireDate, TerminationDate, etc. With a single record for their employment.
@chengchen9032
@chengchen9032 2 года назад
@@CodeOpinion makes total sense, I got it, so a row with termination date being empty/default value when created. Then update to fulfill that information when the corresponding event happened.
@everydreamai
@everydreamai 2 года назад
This specific example is unlikely to scale as I think a business is unlikely to hire and fire one person thousands of times, so just shoving the data in "EmployeeHistory" would probably suffice. That would apply whether you are using events/pub/sub or just an API/ORM, and for RDBMS or a NoSQL store. It is a concern if you are talking about something with a much higher cardinality. Say like clock in/out events for laborers. You might have several per day (breaks, etc) per employee, seeral thousands per year, and then it grows forever as long as someone is employed and working. You have to question then what the business case to read the data back out later is and how you will access it. It may make sense that data is stored by PayPeriod + EmployeeId, which roughly fixes your cardinality to maybe a few dozen or couple hundred no matter how many employees you have and how long they work at the company. To some extent, you could say Derek seems to be putting the cart in front of the horse, he's coming as a developer in a video presumably focused on providing information to other developers, but business should be the main driver to store this extra tabular dimension (history) instead of just a scalar or two (i.e. current employment status or hire/fire dates) It's a good thing to bring up from the dev side, though. There are a lot of really good talking points here, and knowing the difference between the scalar and tabular or event aggregation is good knowledge to have kicking around in your head. It's this sort of knowledge that separates someone who blindly completes a user story and someone who can help steer their business away from information black holes.
@amarul92
@amarul92 Год назад
What if you Aggregate Root has a collection of items, and then somewhere in your code you write AggregateRoot.Collection.Remove(item)? In my case the collection is lets say an Assessment and the collection is Reviewers. But I want to remove one of the Reviewers of the Assessment. Lets say I am using EF and SQL database, What would be the best way to handle that?
@sodreigor
@sodreigor 2 года назад
I can think of several occasions where you should actually hard delete things. The first one that comes to mind is: If I click "Terminate My Account" on facebook for instance, Facebook should hard delete all of the media that I uploaded there. Now the question is: Will facebook actually delete it? I don't know. But should facebook hard delete it? Yes.
@sodreigor
@sodreigor 2 года назад
Just as a complement. I understand that it could exists some information that should be anonymized but still kept for integrity of references to some other data. But the majority of personal data should be hard deleted.
@testuser429
@testuser429 2 года назад
If you want to be GDPR compliant, you should be able to erase all user's personal data.
@markovcd
@markovcd 2 года назад
What about GDPR?
@CodeOpinion
@CodeOpinion 2 года назад
What about it? If you need to delete data, delete it. The point of the video is to capture business concepts if applicable. If you need to delete data, go ahead.
@JackiePrime
@JackiePrime 2 года назад
Doesn't this make your life as a developer much more difficult? For example we use soft delete, and in our EF database context we filter out based on IsDeleted == false as the default. Only when we explicitly requested deleted data is it returned from the API. This means we don't have to think about deleted data. If we went with your approach, we would have to have seperate logic for filtering out deleted records for every entity.
@CodeOpinion
@CodeOpinion 2 года назад
Absolutely would make your life more difficult if your focusing on crud. If your viewing things based on business concepts it's not difficult at all since the concept of deleting likely doesn't exist.
@wboumans
@wboumans 2 года назад
Derek do you use C4 diagrams? If so would you ever do a primer on them?
@CodeOpinion
@CodeOpinion 2 года назад
I don't but I should get maybe Simon on here to do a quick one about it.
@dasfahrer8187
@dasfahrer8187 2 года назад
I'm pretty sure if I'm Peter I want to hard delete all TPS reports.
@CodeOpinion
@CodeOpinion 2 года назад
Yeah. The coversheet. I know, I know. Uh, Bill talked to me about it.
@dasfahrer8187
@dasfahrer8187 2 года назад
@@CodeOpinion Time to go fishing.
@mybackhurts247
@mybackhurts247 2 года назад
Peter Gibbons: what would you say you do here? do you deal with the gd customers so the engineers don't have to? do you have people skills?
@CodeOpinion
@CodeOpinion 2 года назад
🤣
@ujwaldhakal6004
@ujwaldhakal6004 2 года назад
Do you delete user related data from even store to comply with GDPR?
@CodeOpinion
@CodeOpinion 2 года назад
You could delete relevant streams or rebuild them with the relevant user related data omitted.
@brandonpearman9218
@brandonpearman9218 2 года назад
so what you are saying hireEvent = add to db, and terminateEvent = update db... so your answer is softdelete.
@CodeOpinion
@CodeOpinion 2 года назад
Well the point I'm trying to make is the word "delete" makes no sense. You're not deleting anything, you're capturing data related to a business concept (hiring/terminating).
@TheAceInfinity
@TheAceInfinity Год назад
Answering the question of whether to hard delete vs soft delete with the the notion of "adding" things doesn't make any sense. It still doesn't answer the question on whether you should use one or the other because the it's irrelevant to the question, with no alternative provided, and assumes extremely contextual business application requirements that do not apply universally! There's lots of cases where recording a chronological order of events is not the right solution. Not a great answer to the question IMHO.
@CodeOpinion
@CodeOpinion Год назад
You answered it yourself, its "extremely contextual". There's no single answer to the question. The point with the adding is there are more options beyond the soft/hard delete.
@TheAceInfinity
@TheAceInfinity Год назад
@@CodeOpinion That was my point, although I was thinking this video would be about hard and soft delete exclusively and when to choose between one or the other based on the title.
@remigiuszkowalski7405
@remigiuszkowalski7405 2 года назад
​ @CodeOpinion I've read the comments :D Please stop explaining purpose of this video to everyone. It's like riding a bicycle with inverted handlebars - your brain needs to adopt first.
@CodeOpinion
@CodeOpinion 2 года назад
Well I clearly didn't do a good enough job in the video or didn't anticipate the common reaction.
@remigiuszkowalski7405
@remigiuszkowalski7405 2 года назад
​@@CodeOpinion I disagree. You did perfect job! I've been watching your previouse videos when I was learning DDD approach and I had same problems - i was asking question from my limited context. It is so clear for me now and even funny :D
Далее
Data Partitioning! Don't let growth SLOW you down!
10:55
Shared Database between Services? Maybe!
13:51
Просмотров 23 тыс.
НЕ ИГРАЙ В ЭТУ ИГРУ! 😂 #Shorts
00:28
Просмотров 194 тыс.
مسبح السرير #قصير
00:19
Просмотров 1,4 млн
WELCOME TO THE FAMILY, MOE! (Brawl Stars Animation)
00:40
Event Carried State Transfer: Keep a local cache!
11:49
Message Ordering in Pub/Sub or Queue
11:39
Просмотров 11 тыс.
Where should you use gRPC? And where NOT to use it!
10:57
"I NEED data from another service!"...  Do you really?
10:41