9 ms·
PAGNIs: Probably Are Gonna Need Its (2021)
- drewcoo 4y ago[flagged]
- wink 4y ago> API pagination I'd generalize this even more. Never, ever make a json response like `["a", "b"]`, always wrap in an object so you have the freedom to add more top-level keys. `{"foo":["a", "b"]}`.
- z3c0 4y agoI'd add that this extends to data processes as well. Lean pipelines with rigid schemas are great and all, but you're really going to regret not having something more malleable once the system has grown and you have an onslaught of requests for new fields to be added to X solution. Blob storage is cheap. Just dump the whole database and sift through it later.
- muglug 4y ago> having a mechanism that provides detailed logs—including the POST bodies passed to the API—is invaluable. He includes a caveat later to avoid logging PII, but this should have a flashing red warning sign attached.
- adamisom 4y agoIs a logging service/pipeline that removes* PII the only real high-level solution? (* or 'does its best' to remove PII; I feel like there's an immovable object / unstoppable force thing if the answer is "0% PII _ever_!" because that conflicts with the need to log as many things as you can)
- deleted 4y ago[deleted]
- 0xbadcafebee 4y agoYou shouldn't log as many things as you can. You should only log useful things, when they're needed, along with context. Otherwise you have too much noise and not enough signal, and it's easier to leak PII. Applications should have a logging interface that can identify and conceal sensitive information, and data stored in the app/database/etc should have a type that can be denoted as sensitive. You will eventually also want to reduce the amount of logs you generate, so it's useful to have logging levels the same way operating systems do.
- bob1029 4y agoWe do explicit redaction of logs forwarded to us so that we don't have to see any end-customer information. The redaction process occurs automatically in the customer's secure environment, so theoretically it is clean from our perspective. This is indeed a very tricky process, but we have it close enough to make regulators happy. Most of our log information is stored in SQLite and XML, so we can do a lot of parsing magic to achieve determinism.
- rfrey 4y agoI wonder about this a bit. If I'm already storing all the PII in my database, probably on other people's computers via a managed database or at least a cloud server, why are logs different? Is it because they don't receive the same security scrutiny, e.g. any dev can view them versus having special permissions for the database? Or is there more there than authorization that I should be thinking about? (Obviously I'm not talking about logging cleartext passwords, which don't belong in the database either.)
- oandhjakk 4y agoI believe the main concern here, from dealing with clients that have mandated no PII in logs, is both authorisation as well as control. If it’s in your service logs, then it could be in your Splunk logs, it could be in a storage repository and it could be in your requests that you send to the service provider to troubleshoot some issue. Unless there is a valid use case for logging PII (and I can’t think of any which can’t be engineered around) then I think it’s best to avoid it in principle. I think of it as the same as logging passwords, keys or tokens.
- throwaway74829 4y agoPermissions is the big one. Second is potential for DDoS (either intentionally or unintentionally). Third is possibility of "oopsies" via me intentionally or unintentionally including my passwords/sensitive info/what have you in the POST body. Now you have to add branch to look for and scrub sensitive info in your logger -- otherwise my PII has now been logged (and if I were a massive asshole looking for a quick payday, I could throw up a fuss). It's fine in dev, but shouldn't be in prod. Too much liability.
- michaelmior 4y agoI believe this also plays into "right to be forgotten legislation" such as in the GDPR. Suppose you log PII and then a user requests all their PII be deleted. I believe you would then also be required to scrub those logs instead of just dropping records from a database.
- jerf 4y agoA few more in my experience: Database abstractability. Here I don't mean "type of database" like Postgres vs. MySQL vs. Mongo, but making sure in your system you have the ability to target and isolate the entire DB. Integration testing is both vital and slow; as you grow you will be glad you have the ability to run multiple of them at once because they don't interact. With MySQL & Postgres this can be as easy as making sure you code takes the database name as a parameter instead of hard coding it. If your database lacks this feature, take the time to abstract out table names so you can use a certain prefix/suffix for a given test. If you can't quickly recreate the schema and populate with some known set of test data, take the time to write code that will take an existing DB and truncate it back to start or whatever. You need those integration tests, and you need them to not take two hours to run. Get that going at the beginning. I've not yet gotten to the point I need prepopulated schema which is handed out by a central manager, and then the cleanup is run out of the actual test cycle, but I'd be willing to go that far. In 2022 it is likely not a problem at all to have literally a thousand copies of your schema lying around on some test DB server, just to make the tests run fast. Use some versioning solution to make sure they're the right version. There is a LOT of variation in databases here; you will need to tune your process to your DB. In some, schema creation is wicked fast and you can just write all your tests to write out new ones without a problem. In others it is slow but very parallelizable. In others it may be just plain slow, in which case the code to take existing schema and reset them is more valuable. In yet others truncation may be difficult and/or slow due to loose serialization requirements. Do whatever it takes to make your integration tests fast, or at least, as fast as possible. Do not just settle for even simple tests taking 10 minutes because you naively do a slow thing. You really need these to go fast. Authentication and authorization; the earlier you work in some solution, the happier you will be. Sometimes this is easy to retrofit, sometimes it really isn't. Even if you start with authentication and a list of who can do what in the very early phases it'll still prevent you from accidentally depending on having no auth at all. Write your code to be thread/async safe from the beginning, even if you have no use for it yet. You don't want to be in a position where you need it but you've got a 2-year-old code base now built on the deep assumption of single-threading, and it only gets worse as the code base gets larger. It's a slight marginal expense to keep it in mind, it's a project-destroying nightmare to add it back in later. In static languages, get the types declared as early as possible. Get away from (int, int, int, string, string, bool, bool) function signatures as quickly as you can. It's not exactly impossible to retrofit better types later, but it's at the very least a pain in the bum disproportional to the cost of having declared them correctly in the first place. Even if your first stab at real types is wrong, it's still easier to fix them this way because you have the type name as a hook for your IDE, or in the worst case, for sheer grep-based refactoring. (Even in dynamic languages I'd recommend this, but they have more options and the analysis is more complicated. Still, I'd suggest having a "user" that knows how to render itself as a string is better than passing around the user's name or something as a string everywhere and expecting every bit of code that needs to do some user-object-method-y thing to have to look it up themselves.)
- hdjjhhvvhga 4y ago> A kill-switch for your mobile apps Really? I understand the rationale but this is one of the main reasons I prefer desktop apps where kill switches are relatively rare.
- georgyo 4y agoAre they actually that rare? Both Slack and Discord at the very least have one, but that is a small sample size. Both Windows and Mac apps are very eager to self update. A feature they don't have on mobile devices the likely hides these kill switches.
- kiawe_fire 4y agoI think the reason they might appear rare is because the number of desktop apps that depend on a remote server for functionality are less common. For example, a photo editing suite, word processor, or code editor all have the expectation that they be usable entirely offline, and any additional cloud-based features are coded to fail gracefully. As you point out, apps like Slack and Discord don't fall into this camp. Not only is their core functionality expected to be online, they are also Electron apps (basically, embedded Chrome browser) that likely have a thin layer of client logic, and load most resources remotely, just like accessing a web page. Sure, word processors and code editors exist on mobile, and many of them likely work just like their desktop counter parts when offline [1]. But that's not what most mobile apps are. Most mobile apps would be useless without a remote server, and if that remote server needs to make a breaking API change, then you need a way to communicate that. [1] I assume. It's been a while since I've used mobile MS Word. Even then, I suspect these apps will prompt the user to update or else lose cloud service at some point, even if they otherwise continue to work fine locally.
- sethhochberg 4y agoAs much as any sane development team tries to avoid breaking changes, they're virtually inevitable for a long-enough-lived client/server platform. A nice poison pill built in up front lets the ancient clients that for whatever reason aren't being upgraded at least get a nice informational prompt when those breaking changes happen, instead of a potentially uglier failure mode Its one of those things that you think you'll never need because of course you wouldn't make breaking changes, but then at some point an unstoppable force hits an immovable object and this becomes the least-bad way out for user experience
- jjice 4y ago> A bookmarkable interface for executing read-only SQL queries against your database We use Metabase at my work and I love it. It handles visualizations out of the box and I can write SQL like my heart desires, while still being able to help out our designers, customer success, and sales needs. Their "questions" (what they call a query) can be parameterized and added to dashboards and everything works so well. Also one of the few large projects I see that's written in Closure.
- jmull 4y agoThis wouldn't be possible in a lot of the projects I work on. The problem is privileges -- for example, the data you can see depends on whether you're logged in or not, and your group and role when logged in. What I've done instead is provided an interface (bookmarkable) to a set of "rowsets", where the rowset has a name and set of columns, where the columns are filterable, sortable, and/or selectable. Directly behind the rowset is SQL, of course (and/or a view or table), so it's not that much less flexible than SQL directly, but it provides a point where additional filter conditions can be reliably added to enforce privileges (there's also a dev option to see the SQL, if that's needed).
- wgerard 4y agoMy personal addition: Code isolation I've "prematurely" split up code across multiple/classes functions so many times before these huge god functions became set-in-stone and unwieldy. I had a co-worker once who was extremely heavy on YAGNI--and I don't mean that as a pejorative, it was a really helpful check against code solving non-existent problems. They once called me out on a refactor I'd done surreptitiously for a payments flow to split payment states into multiple classes. Serendipity had struck, and I was able to point to a submitted (but not accepted) diff that would've broken the entire payments flow (as opposed to just breaking one state of the flow). I always think about that every time I question whether I'm isolating code prematurely.
- 3pt14159 4y agoPremature class isolation: Usually bad. Some notable exceptions are things like addresses where many times users have multiple, but usually people splitting up the user table and the "user profile" table are just causing headaches. A wide user table is fine. Premature method or function isolation: Usually good. Even if there isn't reuse, the code is usually more readable. def let_in_bar? return self.is_of_age_in_region? and self.is_sober? Is a perfectly fine isolation with very little downside.
- quietbritishjim 4y agoI know your example is just a toy, but it definitely reminds me of heavy handed over-refactoring into tiny one-line functions. There are two problems with that approach: The first is when you're trying to understand what a single function does. If it's 20 lines long but has self-contained logic, that's often easier to understand than referring back to the tiny pieces it's assembled from (even if they're supposedly so self contained you don't need to look at them individually - that's rarely true in practice). On balance, even if a function is a slightly too long, that's usually less bad than one that's in slightly too many little pieces. The second is when you're looking at the file level. When faced with a file with dozens of tiny functions, it's much harder to get a top level understanding than if it has a smaller number of longer functions. The second one is the bigger problem, because understanding a project at the file (and higher) level is typically much harder than understanding what a single function does. Even if breaking up a function into smaller pieces does actually make it easier to understand, but makes the overall project harder to parse, then that's usually a loss overall. Of course, it depends very much on the specifics of the situation though, and certainly a long function broken down into logical pieces can actually make the overall project easier to understand.
- AndreasHae 4y agoI‘m interested in the reasoning why API pagination is hard to add later, or rather what the benefit is of „leaving space“ in the API response while in reality returning all items at once. Wouldn’t have to adapt the way the frontend consumes the API either way, keeping track of the current list state? Or is that what the author meant, that you should always write your list UIs as if they consumed a paginated API?
- justin_oaks 4y agoI agree that the author wasn't quite clear on this point. If you control both the client and the API, then pagination is something you can add in later. But setting up pagination early may make sense if the client isn't in your control. The author gave the example of the an old mobile app that users don't update. The client is also out of your control if it's a public API that users call with whatever client code they choose. That said, I'm not sure how setting up "fake" pagination is helpful if the client isn't already coded to use pagination responses from the server. So I'll have to assume the author means that any client you provide already has pagination logic built-in.
- michaelmior 4y agoThis is a narrow view, but one example is that if you're using JSON and your API response looks like this: [{id: 1, …},…] Then you can't easily add pagination without changing the structure of the response. Whereas if you have something like this: {results: [{id: 1, …},…]} then you can add in whatever other properties you need and this change can be made without immediately breaking any existing applications. Of course, it's still true that you'll have to rewrite the frontend to actually implement pagination, but it does do something for backward compatibility. You could probably still have old versions of the application at least display the first page of results without changes.
- jmull 4y agoThat's the best interpretation I could come up with as well. I think the general idea is to leave room in distributed APIs to add metadata later. It's not really just about potential pagination, but leaving yourself a way to add/change functionality later without updating all the clients in lockstep with the server (always awkward and there's never a way to pull it off 100% cleanly).
- swyx 4y agomy submission for PAGNI: Preemptive Pluralizations https://www.swyx.io/preemptive-pluralization https://www.swyx.io/preemptive-pluralization Before you write any code — ask if you could ever possibly want multiple kinds of the thing you are coding. If yes, just do it. It is a LOT easier to scale code from a cardinality of 2 to 3 than it is to refactor from a cardinality of 1 to 2. Example: - You assume that one team has many users, and correspondingly, one user belongs to one team. - Eventually, you find that a user may need multiple teams. This is actually fantastic for your business! - But you are depressed because you now have to spend 2 months refactoring every line of code and database schema that assumed the one-to-one mapping
- vaidhy 4y agoThe more general rule I follow is that there are only three cardinalities in software - 0, 1, and many. Default should be many. Any other limits you put is likely to be incorrect.
- kragen 4y agoThis is appealing, but taking this advice seriously means that all your relationships are many-to-many, until you optimize some of them to be one-to-many or one-to-one. This clashes extremely strongly with the currently popular approaches to software development (OO, procedural, Lisp/ML-style functional, SQL, etc.), which have an extremely strong default of cardinality 1, inflicting lots of extra work on you for many-to-many relationships. You'd never have a member of a struct or a class start out as an int or a string; they would always be int lists, string lists, etc. Points would have a list of X coordinates rather than a single X coordinate; interpreters would interpret a list of programs; 3-D objects would have a list of transform matrices rather than a single transform matrix; files would have a list of owners. (And of course in languages like C and Golang when you nest a Foo object inside a Bar object, you are foreclosing the possibility of that Foo having the same relationship with some other Bar object as well; you need pointers.) Systems that do support that kind of thing in one way or another include Prolog, miniKANREN, the APL family, and Pick. But Prolog and APL only support it to a very limited extent, and I've never used Pick or miniKANREN.
- 0xbadcafebee 4y agoPAGNI is basically a form of Shift Left. https://www.dynatrace.com/news/blog/what-is-shift-left-and-what-is-shift-right/ https://www.dynatrace.com/news/blog/what-is-shift-left-and-w... https://devopedia.org/shift-left https://devopedia.org/shift-left
- kotlin2 4y agoI don’t think you’ll need most of these things. My metric would be whether or not your app would continue to function without these things. Using this metric: Kill switch: may be required, but unlikely. Automated deploys: definitely not necessary. Your app can still function if you deploy manually. CI: definitely not necessary. Your app can still function without automatically run integration tests. It can run without any integration tests at all. API pagination: depends on the API. Detailed API logs: not necessary. You can add logging as problems arise. Even when I add detailed logging ahead of time, I often find I missed the one crucial piece of information needed to make using the logs possible during an investigation. SQL query dashboard: not necessary. You can easily use a script interface or CLI that stores history.
- xapata 4y ago> I often find I missed the one crucial piece of information needed to make using the logs possible during an investigation. This may be a bit of confirmation bias, or ... I'm not sure what the right term is. The times you didn't have the necessary information stick out in your memory, because they were serious problems. The times you did have the right information logged you solved the problem quickly and it never became a fire.
- jaywalk 4y agoThe article describes precisely why proactively adding these things is (probably) necessary. For example, the kill switch: yeah, you hope you won't need it. But if the time comes that you do, it's too late to add it.
- kotlin2 4y agoYou can use that argument when adding anything.
- solatic 4y agoControversial opinion: Don't write tests first. If you're not writing tests, you don't need CI to run tests, and CD isn't safe. Write tests only: (a) if the algorithm is so complicated, that you need unit testing to ensure that you're writing it correctly in the first place (b) if, when, and after you earn revenue from the code Why would you waste your time proving that something you wrote works, if you don't have product-market fit, and you need to throw it all out next week to try to satisfy the market with something different? Just make sure you have the discipline to go back and actually add edge-to-edge / integration testing after you make the sale, and not go straight to the next feature, leaving the lack of testing as technical debt.
- john-tells-all 4y agoAbsolutely -- Tests are a business investment, and a business expense. A question is: "what is the business consequence if this code doesn't work as expected?" If the code is frontend stuff, then maybe tests won't pay off. If the code is "calculate total and taxes for user buying products", then yes, you probably do want to write tests. If you don't write them first, then they might not get done until there's a "big bang" of "gee we need to write tests for the last 10k lines of code over the weekend". Or worse: code might or might not be correct in the past, but you can't tell how many users were affected. Tests are a business investment, and it's worth a discussion to find out risk tolerance.
- layer8 4y agoYour unit tests shouldn’t need CI to run, period. Only integration tests might need to, but also not necessarily (the “continuous” part, that is).
- deleted 4y ago[deleted]
- ParetoOptimal 4y ago> Why would you waste your time proving that something you wrote works, if you don't have product-market fit, What if your poor execution and untested software simply makes it appear you don't have product-market fit?
- bena 4y agoI like the YAGNI principle. It doesn't mean "never do it". It means "don't try to anticipate all your needs". Because you can sit around and come up with scenario after scenario to defend including almost everything. Get it working. Worry about everything else after that is accomplished. Will you eventually need a kill switch? Maybe. Do you need it to build a proof of concept? You Ain't Gonna Need It. Do you have enough results for pagination? Eventually. To build the API for your first test? You Ain't Gonna Need It. Because the rest of the sentence is "until you do". Eventually you will need a lot of this stuff, but sometimes you actually don't need it. Don't waste time fulfilling non-existent needs.