{"id":1405,"date":"2024-03-02T14:12:25","date_gmt":"2024-03-02T14:12:25","guid":{"rendered":"https:\/\/www.muratyaman.co.uk\/blog\/?p=1405"},"modified":"2024-03-03T08:51:41","modified_gmt":"2024-03-03T08:51:41","slug":"most-developers-dont-see-the-technical-debt-on-v1","status":"publish","type":"post","link":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/2024\/03\/most-developers-dont-see-the-technical-debt-on-v1\/","title":{"rendered":"Most developers don&#8217;t see the technical debt on V1"},"content":{"rendered":"<p>Existence of V1 (the very first version of our solution) actually shows our hope that one day we will be &#8220;allowed&#8221; to be working on V2!<\/p>\n<p><strong>Tech debt<\/strong><\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Technical_debt\">https:\/\/en.wikipedia.org\/wiki\/Technical_debt<\/a><\/p>\n<p>There are ugly parts, we know, we deliver something quickly under pressure &#8211; but it works (for now). Most of us don&#8217;t &#8220;see&#8221; them. It is usually because of lack of sufficient experience in the field.<\/p>\n<p>Most managers don&#8217;t &#8220;understand&#8221; technology; never mind the technical debt!<\/p>\n<p>If they are not willing to give us time, we have to (sneakily) over-estimate the new features requested in order to be able to resolve technical debt gradually. In the worst case, we may be required to shut the &#8220;business&#8221; for maintenance!<\/p>\n<p><strong>Don&#8217;t be naive!<\/strong><\/p>\n<p>Long time ago, I caught a &#8220;naive&#8221; looking SQL bug in a system I was working on:<\/p>\n<p><code><br \/>\nSELECT *<br \/>\nFROM [a-table]<br \/>\nWHERE id IN (...[parameters])<br \/>\n<\/code><\/p>\n<p>When I printed it on a MS Word document, the team was shocked: it was over 100 pages long! The query was over 2MBs. MySQL server was not happy: it rejected the query because it was <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/packet-too-large.html\">configured<\/a> to reject payloads over 2MB!<\/p>\n<p>Once I crashed a MySQL server when I tried to add a column to a table!<\/p>\n<p><code><br \/>\nALTER TABLE [a-table]<br \/>\nADD COLUMN [a-column] VARCHAR(100);<br \/>\n<\/code><\/p>\n<p>In the past, MySQL server developers were also naive: they did not check the disk requirements of DDL commands before executing them.<\/p>\n<p><strong>Refactor<\/strong><\/p>\n<p>Another time, a system we developed almost stopped working after I went on holiday! I had to spent 2 weeks in &#038; out of an internet cafe trying to find and fix the issue. Firebird SQL database server struggled with the load when there were &#8220;many&#8221; records in a table. We were using <a href=\"https:\/\/firebirdsql.org\/file\/documentation\/chunk\/en\/refdocs\/fblangref50\/fblangref50-ddl-trigger.html\">triggers<\/a> inefficiently! A trigger can work perfectly for a single row but it may not work as expected for many rows. We had to move the logic to the application server and optimise the business logic.<\/p>\n<p>A database is usually the bottleneck in a classic 3-tier architecture: App, API, DB. Take advantage of using multiple API server instances and use their computational power.<\/p>\n<p><strong>Test, test, test! &#8230; and automate! &#8230; but moderate!<\/strong><\/p>\n<p>When a solution works for most of our test scenarios, it does not mean that it will work 100% of the time: one day it will need to handle a case that could happen 0.1% of the time.<\/p>\n<p>It&#8217;s about considering moderation: we can not automate every task. We should keep an eye on upgrade operations &#8211; i.e. software releases in production environments.<\/p>\n<p><strong>Don&#8217;t be a fanatic!<\/strong><\/p>\n<p>We must see the imperfections of our stuff! We should know about the pros &#038; cons (or limitations) of our solutions; the software libraries, frameworks, systems that we rely on. We should be able to talk about them without twitching!<\/p>\n<p><a href=\"https:\/\/graphql.org\/\">GraphQL<\/a> is the best way we can create an API these days.<\/p>\n<p><strong>Pros<\/strong><\/p>\n<ol>\n<li>we can avoid over-fetching data<\/li>\n<li>we can avoid under-fetching data<\/li>\n<li>we can use type safety for inputs and outputs<\/li>\n<li>we can use code generation tools to scaffold code for App &#038; API.<\/li>\n<li>server will use CPU, memory and network gracefully<\/li>\n<li>it is less &#8220;chattier&#8221; than REST or gRPC (as the App does not need to send many serial or parallel requests)<\/li>\n<li>it provides the best developer experience on client-side (as it hides the complexity of working with many microservices for instance)<\/li>\n<li>it leads to better user experience (as the network speed between user and servers is slower than the speed between the servers)<\/li>\n<li>we can send a batch of commands to the server<\/li>\n<\/ol>\n<p><strong>Cons<\/strong><\/p>\n<p>ol><\/p>\n<li>model relationships may actually lead to over-fetching data: beware of <a href=\"https:\/\/shopify.engineering\/solving-the-n-1-problem-for-graphql-through-batching\">1 + N queries<\/a> which can be solved by batching the queries using a data loader library<\/li>\n<li>some App developers may not actually try to retrieve only the data they need; so beware if you are deploying public GraphQL APIs and use a query <a href=\"https:\/\/apim.docs.wso2.com\/en\/3.2.0\/learn\/rate-limiting\/graphql-api\/query-complexity-limitation\/\">complexity score calculator<\/a> with a limit<\/li>\n<li>some App developers may batch so many commands together and it may lead to huge input and output payloads &#8211; not graceful usage of CPU, memory and network neither on server-side nor on client-side! Limiting complexity score can help.<\/li>\n<li>GraphQL (or REST, or even HTTP v1) is not designed to handle files &#8211; use a proper file server to exchange files; so GraphQL can easily refer to the file URLs &#8211; ideally using <a href=\"https:\/\/web.dev\/articles\/performance-http2\">HTTP v2<\/a>.<\/li>\n<\/ol>\n<p>BTW, there is NO V1 in GraphQL world \ud83d\ude09<\/p>\n<p>Image from Unsplash: <a href=\"https:\/\/unsplash.com\/photos\/blue-and-white-wooden-house-on-green-grass-field-during-daytime-1UMrSoItdDE\">https:\/\/unsplash.com\/photos\/blue-and-white-wooden-house-on-green-grass-field-during-daytime-1UMrSoItdDE<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Existence of V1 (the very first version of our solution) actually shows our hope that one day we will be &#8220;allowed&#8221; to be working on V2!<\/p>\n","protected":false},"author":2,"featured_media":1406,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[55,200,57,33],"class_list":["post-1405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-firebird","tag-graphql","tag-mysql","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1405"}],"version-history":[{"count":7,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1405\/revisions"}],"predecessor-version":[{"id":1413,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1405\/revisions\/1413"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media\/1406"}],"wp:attachment":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}