TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

YAGRI: You are gonna read it

329 pointsby escot28 days ago

36 comments

crazygringo27 days ago
These are not decisions that should be taken solely by whoever is programming the backend.<p>They need to be surfaced to the product owner to decide. There may very well be reasons pieces of data should <i>not</i> be stored. And all of this adds complexity, more things to go wrong.<p>If the product owner wants to start tracking every change and by who, that can completely change your database requirements.<p>So have that conversation properly. Then decide it&#x27;s either not worth it and don&#x27;t add any of these &quot;extra&quot; fields you &quot;might&quot; need, or decide it is and fully spec it out and how much additional time and effort it will be to do it as a proper feature. But don&#x27;t do it as some half-built just-in-case &quot;favor&quot; to a future programmer who may very well have to rip it out.<p>On a personal project, do whatever you want. But on something professional, this stuff needs to be specced out and accounted for. This isn&#x27;t a programming decision, it&#x27;s a product decision.
评论 #43779339 未加载
评论 #43781181 未加载
评论 #43784747 未加载
评论 #43779746 未加载
评论 #43779360 未加载
评论 #43783031 未加载
评论 #43780697 未加载
评论 #43785651 未加载
评论 #43780535 未加载
KronisLV27 days ago
I don&#x27;t get why all of the big RDBMSes (PostgreSQL, MariaDB&#x2F;MySQL, SQL Server, Oracle, ...) don&#x27;t seem to have built in support for soft deletes up front and center?<p><pre><code> CREATE TABLE ... WITH SOFT DELETES </code></pre> Where the regular DELETE wouldn&#x27;t get rid of the data for real but rather you could query the deleted records as well, probably have timestamps for everything as a built in low level feature, vs having to handle this with a bunch of ORMs and having to remember to put AND deleted_at IS NULL in all of your custom views.<p>If we like to talk about in-database processing so much, why don&#x27;t we just put the actual common features in the DB, so that toggling them on or off doesn&#x27;t take a bunch of code changes in app, or that you&#x27;d even be able to add soft deletes to any legacy app that knows nothing of the concept, on a per table basis or whatever.
评论 #43781954 未加载
评论 #43786238 未加载
评论 #43782630 未加载
评论 #43782075 未加载
评论 #43783178 未加载
评论 #43781213 未加载
评论 #43791203 未加载
评论 #43784369 未加载
alganet28 days ago
*_at and *_by fields in SQL are just denormalization + pruning patterns consolidated, right?<p>Do the long walk:<p>Make the schema fully auditable (one record per edit) and the tables normalized (it will feel weird). Then suffer with it, discover that normalization leads to performance decrease.<p>Then discover that pruned auditing records is a good middle ground. Just the last edit and by whom is often enough (ominous foreshadowing).<p>Fail miserably by discovering that a single missing auditing record can cost a lot.<p>Blame database engines for making you choose. Adopt an experimental database with full auditing history. Maybe do incremental backups. Maybe both, since you have grown paranoid by now.<p>Discover that it is not enough again. Find that no silver bullet exists for auditing.<p>Now you can make a conscious choice about it. Then you won&#x27;t need acronyms to remember stuff!
评论 #43778921 未加载
评论 #43779060 未加载
评论 #43778667 未加载
arialdomartini27 days ago
While I like the YAGRI principle very much, I find that adding<p>- updated_at<p>- deleted_at (soft deletes)<p>- created_by etc<p>- permission used during CRUD<p>to every table is a solution weaker than having a separate audit log table.<p>I feel that mixing audit fields with transactional data in the same table is a violation of the separation of concerns principle.<p>In the proposed solution, updated_at only captures the last change only. A problem that a separate audit log table is not affected to.
评论 #43779883 未加载
评论 #43780779 未加载
评论 #43779577 未加载
gorgoiler28 days ago
Additionally, mutable fields will quite often benefit from having a separate <i>edit</i> table which records the old value, the new value, who changed it, and when. Your main table’s <i>created</i> and <i>updated</i> times can be a function of (or a complement to) the <i>edit</i> table.<p>It is tempting to supernormalize everything into the relations <i>object(id, type)</i> and <i>edit(time, actor_id, object_id, key, value)</i>. This is getting dangerously and excitingly close to a graph database implemented in a relational database! Implement one at your peril — what you gain in schemaless freedom you also lose in terms of having the underlying database engine no longer enforcing consistency on your behalf.
评论 #43779428 未加载
评论 #43779513 未加载
评论 #43779592 未加载
reillyse28 days ago
One thing I do quite frequently which is related to this (and possibly is a pattern in rails) is to use times in place of Booleans.<p>So is_deleted would contain a timestamp to represent the deleted_at time for example. This means you can store more information for a small marginal cost. It helps that rails will automatically let you use it as a Boolean and will interpret a timestamp as true.
评论 #43778372 未加载
评论 #43778083 未加载
评论 #43778596 未加载
评论 #43777788 未加载
arjonagelhout28 days ago
A little while back, I had a conversation with a colleague about sorting entries by &quot;updated at&quot; in the user interface, and to my surprise this was not added by the backend team.<p>Many of these &quot;we are going to need it&quot;s come from experience. For example in the context of data structures (DS), I have made many &quot;mistakes&quot; that I do correctly a second time. These mistakes made writing algorithms for the DS harder, or made the DS have bad performance.<p>Sadly, it&#x27;s hard to transfer this underlying breadth of knowledge and intuition for making good tradeoffs. As such, a one-off tip like this is limited in its usefulness.
评论 #43777587 未加载
评论 #43777440 未加载
shaunofthedev28 days ago
The perils of UI design wagging the horse.<p>I like the heuristics described here. However if these things aren&#x27;t making it into a product spec where appropriate, then I smell some dysfunction that goes beyond what&#x27;s being stored by default.<p>Product need (expressed as spec, design, etc) should highlight the failure cases where we would expect fields like these to be surfaced.<p>I&#x27;d hope that any given buisness shouldn&#x27;t need someone with production database access on hand to inform as to why&#x2F;when&#x2F;how &#x27;thing&#x27; was deleted. Really we&#x27;d want the user (be it &#x27;boss&#x27; or someone else) to be able to access that information in a controlled manner.<p>&quot;What information do we need when something goes wrong?&quot;. Ask it. Drill it. Ask it again.<p>That said, if you can&#x27;t get those things, this seems a fine way to be pragmatic.
评论 #43778789 未加载
hoipaloi28 days ago
Counter point: &quot;Soft Deletion Probably Isn&#x27;t Worth It&quot; <a href="https:&#x2F;&#x2F;brandur.org&#x2F;soft-deletion" rel="nofollow">https:&#x2F;&#x2F;brandur.org&#x2F;soft-deletion</a>
评论 #43778152 未加载
al_borland28 days ago
I agree with this as written, as think it&#x27;s important to have some degree of forethought when building out the DB to plan for future growth and needs.<p>That said, the monkey paw of this would be someone reading it and deciding they should capture and save all possible user data, &quot;just in case&quot;, which becomes a liability.
mkhalil28 days ago
Event-sourcing solves this. And with how cheap storage is, it should be more prevalent in the industry. IMO the biggest thing holding it back is that there isn&#x27;t a framework that&#x27;s plug-and-play (say like Next.js is to React) that provides people with that ability.<p>I&#x27;ve been working on one in Typescript (with eventual re-writes in other langs. like Rust and Go), but it&#x27;s difficult even coming up with conventions.
评论 #43777798 未加载
评论 #43777499 未加载
evanmoran28 days ago
Just curious, how do people feel about this general style of soft deletes currently? Do people still use these in production or prefer to just delete fully or alternatively move deleted rows to a separate tables &#x2F; schema?<p>I find the complexity to still feel awkward enough that makes me wonder if deleted_at is worth it. Maybe there are better patterns out there to make this cleaner like triggers to prevent deletion, something else?<p>As for the article, I couldn&#x27;t agree more on having timestamps &#x2F; user ids on all actions. I&#x27;d even suggest updated_by to add to the list.
评论 #43778258 未加载
评论 #43777576 未加载
评论 #43778153 未加载
评论 #43777687 未加载
评论 #43780665 未加载
评论 #43777607 未加载
评论 #43784184 未加载
im_anon_on_hn28 days ago
As an acronym, it&#x27;s easy to be misremembered as &quot;You ARENT gonna read it&quot; (based on the popularity of yagni) - and have the opposite advice spread..
评论 #43778633 未加载
评论 #43778740 未加载
ltbarcly327 days ago
This is good advice except for deleted_at. Soft deletion is rarely smart. Deleted things just accumulate and every time you query that table is a new opportunity to forget to omit deleted things. Query performance suffers a lot. It&#x27;s just a needless complexity.<p>Instead, just for the tables where you want to support soft delete, copy the data somewhere else. Make a table like `deleteds (tablename text not null, data jsonb not null default &#x27;{}&#x27;)` that you can stuff a serialized copy of the rows you delete from other tables (but just the ones you think you want to support soft delete on).<p>The theory here is: You don&#x27;t actually want soft delete, you are just being paranoid and you will never go undelete anything. If you actually do want to undelete stuff, you&#x27;ll end up building a whole feature around it to expose that to the user anyway so that is when you need to actually think through building the feature. In the meantime you can sleep at night, safe in the knowledge that the data you will never go look at anyway is safe in some table that doesn&#x27;t cause increased runtime cost and development complexity.
sgarland28 days ago
&gt; But I&#x27;ve never heard someone complain about a table having too many timestamps.<p>I do. Each one is 8 bytes. At the billions of rows scale, that adds up. Disk is cheap, but not free; more importantly, memory is not cheap at all.
IshKebab27 days ago
Yes! Why something happened is incredibly important. Gitlab made this mistake <i>hard</i>. We have a medium sized instance with some complex CI pipelines and often they&#x27;ll just get cancelled and it doesn&#x27;t say why or even who by. And anyone can do it! The only option is to ask the entire company &quot;did anyone cancel this?&quot;
r7n27 days ago
We did exactly this when designing StatleyDB. We realized there are a set of metadata fields[0] that almost everyone needs when modeling data. Our approach takes this a step further in that we always track these fields transparently so if you forget to add them to your schema initially for any reason, that&#x27;s okay, you can always add them later!<p>[0] <a href="https:&#x2F;&#x2F;docs.stately.cloud&#x2F;schema&#x2F;fields&#x2F;#metadata-fields" rel="nofollow">https:&#x2F;&#x2F;docs.stately.cloud&#x2F;schema&#x2F;fields&#x2F;#metadata-fields</a>
seveibar28 days ago
Agree, although the acronym in the article could be interpreted to mean “you are going to read it, so index it appropriately”, which is sort of bad advice and can lead to overindexing. There is probably something better for “add appropriate and conventional metadata” (the author suggests updated_at, created_at etc)<p>Not a huge fan of the example of soft delete, i think hard deletes with archive tables (no foreign key enforcement) is a much much better pattern. Takes away from the main point of the article a bit, but glad the author hinted at deleted_at only being used for soft deletes.
PaulHoule27 days ago
Funny I&#x27;ve been developing an adaption layer that implements the functionality that I use in<p><a href="https:&#x2F;&#x2F;docs.python-arango.com&#x2F;en&#x2F;main&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.python-arango.com&#x2F;en&#x2F;main&#x2F;</a><p>over tables in Postgres that has a PRIMARY _key and a JSONB document field. The issue is that I have a number of prototypes I&#x27;ve developed with arangodb but the license is awful and I don&#x27;t feel like I can either open source <i>or</i> commercialize any of them until I&#x27;m running on an open source database.<p>It&#x27;s a fun project because I don&#x27;t need to support everything in python-arango, in fact I don&#x27;t even need to support 100% of the features I use because I am free to change my applications. Also it&#x27;s a chance to make the library that I <i>really</i> want to use so already it has real integer and UUID primary keys.<p>I just added a feature to have the library manage _created and _updated fields not just because I thought it was good in general but it was a feature I needed for a particular application, a crawler that fetches headlines from the HN API. I want to fetch headlines right away so I can avoid submitting duplicates but I also want accurate counts of how many votes and comments articles got and that involves recrawling again in two weeks. Of course _created and _updated are helpful for that.
yellowapple27 days ago
The problem with updated_at and updated_by is that a given record could experience multiple updates by multiple people at multiple times, and you&#x27;d only have visibility into the most recent.<p>The logical conclusion here is to log the updates (and creations and deletions and undeletions and such) themselves:<p><pre><code> CREATE TABLE foo_log (id, foo_id, whodunnit, action, performed_at, column_1, column_2, -- ... column_n); </code></pre> Technically you don&#x27;t even need the &quot;foo&quot; table anymore, since you can reconstruct its contents by pulling the most recent transaction for a given foo_id and discarding the reconstructed record if the most recent action on it was a deletion. Probably still a good idea to create a view or somesuch for the sake of convenience, but the point of this is that the log itself becomes the record of truth - and while this approach does cost some disk space (due to duplicated data) and read performance (due to the more complex query involved), it&#x27;s invaluable for tracking down a record&#x27;s full lifecycle. Even better if you can enforce append-only access to that table.<p>This is a pretty typical approach for things like bookkeeping and inventory management (though usually those are tracking the deltas between the old and new states, instead of recording the updated states directly as the above example would imply).
guy426127 days ago
Author is very kind! In practice, many times I saw only the CR&#x2F;CRU of CRUD getting implemented.<p>For example: as a company aspires to launch its product, one of the first features implemented in any system is to add a new user. But when the day comes when a customer leaves, suddenly you discover no one implemented off-boarding and cleanup of any sort.
simonw27 days ago
Related from a few years ago: PAGNIs, for Probably Are Gonna Need Its - <a href="https:&#x2F;&#x2F;simonwillison.net&#x2F;2021&#x2F;Jul&#x2F;1&#x2F;pagnis&#x2F;" rel="nofollow">https:&#x2F;&#x2F;simonwillison.net&#x2F;2021&#x2F;Jul&#x2F;1&#x2F;pagnis&#x2F;</a>
Aldipower27 days ago
Five years ago everybody would lough about &quot;soft deletes&quot; or &quot;marked as deleted&quot;. Whoever thought this is a good idea from a data protection perspective? You also lying in the face of your users with such a behavior. Shame.
评论 #43780536 未加载
silisili27 days ago
I don&#x27;t like general advice like this, because it&#x27;s too general. For many, it&#x27;s probably good advice. For others, not so much.<p>Anyone who has worked at a small company selling to large B2B SaaS can attest we get like 20 hits a day on a busy day. Most of that is done by one person in one company, who is probably also the only person from said company you&#x27;ve ever talked to.<p>From that lens, this is all overkill. It&#x27;s not bad advice, it&#x27;s just that it will get quoted for scenarios it doesn&#x27;t apply. Which also apply to K8S, or microservices at large even, and most &#x27;do as I say&#x27; tech blogs.
评论 #43780069 未加载
optician_owl27 days ago
It&#x27;s a terrible post. What it suggests is to turn your head off and follow overly generalised principle. I guess when somebody invent yet another acronym it is a red flag.<p>Data has its own life cycles in every area it passes through. And it&#x27;s part of requirements gathering to find those cycles: the dependent systems, the teams, and the questions you need to answer. Mindlessly adding fields won&#x27;t save you in every situation.<p>Bonus point: when you start collecting questions while designing your service, you&#x27;ll discover how mature your colleagues&#x27; thinking is.
nailer28 days ago
I have a different way of thinking about this: data loss. If you are throwing away data about who performed a delete it is a data loss situation. You should think about whether that’s OK. It probably isn’t.
nexo-v127 days ago
Shipped and supported enough startup apps to learn this the hard way: users will delete things they shouldn’t, and you will be asked to explain or undo it. Soft deletes and basic metadata (created_at, deleted_by, etc.) have saved me multiple times — not for some future feature, just for basic operational sanity.
smitty1e28 days ago
YAGRI proponents organized themselves into a community to develop their...YAGRIculture.<p>I&#x27;ll show myself out.
zie28 days ago
Literally just have a good audit log and then you get all of this for free and more.
8bitme27 days ago
For `updated_at` and `deleted_at` making them nullable and null until touched is incredibly useful.<p>Answering queries like how many of these were never updated? Or how many of these were never cancelled?
ffitch28 days ago
curious that both YAGNI and YAGRI arguments could realistically be made for the same fields. guess it boils down to whether someone’s YAGRI is stronger than their colleague’s YAGNI ( :
KingOfCoders27 days ago
OT As the great Alone (&quot;Last Psychiatrist&quot;) said, &quot;if you read it, it&#x27;s for you&quot; - IYRIIFY
oofManBang28 days ago
How do you distinguish from &quot;you aren&#x27;t gonna read it&quot;? The acronym is poorly designed.
imoreno27 days ago
It&#x27;s not really YAGNI if you need it to debug, is it?
kamatour27 days ago
Why can&#x27;t databases just remember stuff we delete, like a trash can?
评论 #43783645 未加载
评论 #43785947 未加载
drewcoo28 days ago
To every point there is a counterpoint. So what?
评论 #43778279 未加载