<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ande</title>
    <description>The latest articles on DEV Community by Ande (@aslasn).</description>
    <link>https://dev.to/aslasn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F92637%2Ffc996c11-cc83-4214-91e4-7aba3e826689.png</url>
      <title>DEV Community: Ande</title>
      <link>https://dev.to/aslasn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aslasn"/>
    <language>en</language>
    <item>
      <title>Throwing exceptions vs Returning failure object</title>
      <dc:creator>Ande</dc:creator>
      <pubDate>Sun, 02 Aug 2020 14:09:51 +0000</pubDate>
      <link>https://dev.to/aslasn/throwing-exceptions-vs-returning-failure-object-egd</link>
      <guid>https://dev.to/aslasn/throwing-exceptions-vs-returning-failure-object-egd</guid>
      <description>&lt;p&gt;I'm aware that clean And maintainable code is more important than premature optimizations. Throwing exceptions seems to be more suggestive than return codes. But i'm not talking about return codes. Here a example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;SignIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userExist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;logics&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userExist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;UserNotExistError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;generateToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the same but with return objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;SignIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userExist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;logics&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;userExist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;no-user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;generateToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second looks like a better option &lt;strong&gt;to me&lt;/strong&gt;. Because handling exceptions is theoretically less performant, and with try/catch is it's sync. Besides over time there'll be lots of exceptions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;UserNotExistError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UserExistError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ValidationError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;DBError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;QueryFailedError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UnknownError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FunctionSpecificError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OtherFunctionSpecificError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I myself noticed few millisecs delay in requests when handling exceptions on my computer and on a relatively small project. It can add up in a larger scale.&lt;/p&gt;

&lt;p&gt;I'm by no means not saying not to use exceptions. They're quite handy. But why everywhere, when a signup/signin fails, something doesn't exist or does..&lt;/p&gt;

&lt;p&gt;The lots of SO threads seem to discuss more about theory and less specific details. What about your opinion? How have you been doing this? &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>exceptions</category>
      <category>functional</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Pub/Sub model vs Task Queues</title>
      <dc:creator>Ande</dc:creator>
      <pubDate>Mon, 27 Jul 2020 11:04:52 +0000</pubDate>
      <link>https://dev.to/aslasn/pub-sub-model-vs-task-queues-4i83</link>
      <guid>https://dev.to/aslasn/pub-sub-model-vs-task-queues-4i83</guid>
      <description>&lt;p&gt;My perspective on publish/subscribe model is that it's running on the application level without a persistent queue like rabbitmq. All it is doing for me is making tasks like sending users a verification mail asynchronous. Where mailing might take up to a few hundred milliseconds.&lt;/p&gt;

&lt;p&gt;Now I can achieve the same with task queues. Which seem to be more viable since once the task is queued, it's there even after a server crash. Even better in a distributed system, systems running long/complex tasks etc.&lt;/p&gt;

&lt;p&gt;I wanna talk simple for most everyday cases like sending emails, analytics, doing some complex database queries.&lt;/p&gt;

&lt;p&gt;Adding a job schedule requires me to do some structuring in the codebase and managing those queues and logs. While it might be a good use case for lots of tasks, why should i even bother for cases where i can get away with a pub/sub layer. What are the constrains I am not aware of or wrong about?&lt;/p&gt;

&lt;p&gt;I would like to know your opinion on this. &lt;/p&gt;

</description>
      <category>discuss</category>
      <category>pubsub</category>
      <category>taskqueue</category>
      <category>node</category>
    </item>
    <item>
      <title>Handling server/application crashes</title>
      <dc:creator>Ande</dc:creator>
      <pubDate>Sun, 26 Jul 2020 08:22:19 +0000</pubDate>
      <link>https://dev.to/aslasn/handling-server-application-crashes-3p6m</link>
      <guid>https://dev.to/aslasn/handling-server-application-crashes-3p6m</guid>
      <description>&lt;p&gt;I'll need some practical advice on this.&lt;br&gt;
The crash can happen anytime. When it crashes there is probably multiple if not thousands of operations running if it's a popular application.&lt;/p&gt;

&lt;p&gt;Like a simple example would be signing up. Steps include checking the user, creating record, create token, send verification mail, dispatch some events, those events doing their jobs and bunch of other stuff. The crash can happen in more complex scenario creating multiple insert/update queries and stuff.&lt;/p&gt;

&lt;p&gt;This is what i could figure out.&lt;br&gt;
Creating logs of two state of each operation. Like &lt;code&gt;starting_op1&lt;/code&gt; and &lt;code&gt;done_op1&lt;/code&gt;. So when the server boots up again, it can restore where it left off by checking what started but couldn't finish.&lt;br&gt;
But if I push logs of each operation, it creates an overhead and potential latency in some applications where it matters. Plus If I'm using something like redis(even with persistence) for the state logs, the server crash can affect these logs too, provided that not many will use a second server for this.&lt;/p&gt;

</description>
      <category>crash</category>
      <category>discuss</category>
      <category>server</category>
    </item>
    <item>
      <title>Ping to dev.to (ASIA -&gt; NYC) is faster than reasonable </title>
      <dc:creator>Ande</dc:creator>
      <pubDate>Sun, 24 Nov 2019 02:50:42 +0000</pubDate>
      <link>https://dev.to/aslasn/ping-to-dev-to-asia-nyc-is-faster-than-imaginable-45f5</link>
      <guid>https://dev.to/aslasn/ping-to-dev-to-asia-nyc-is-faster-than-imaginable-45f5</guid>
      <description>&lt;p&gt;I wondered why dev.to is so fast. I read all available posts there is about dev.to&lt;/p&gt;

&lt;p&gt;Today, I pinged dev.to and response time was &amp;lt; 60ms. The server location showed NYC, fastly. I tried pinging linode, vultr, digital ocean NYC data-centers and non of them showed &amp;lt; 200ms. Mostly between 200-300ms. I even pinged my empty new fresh NYC server and it was still above 200ms.&lt;/p&gt;

&lt;p&gt;To be extra sure if dev.to really has NYC servers, I pinged from one of my NYC server and dev.to has multiple NYC IPs and all ~1ms.&lt;/p&gt;

&lt;p&gt;How come fastly or dev.to response so fast? Where no others can't. What I'm missing? Is fastly really that fast? It doesn't even reasonable to response from NYC when I'm far in asia&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>fastly</category>
    </item>
  </channel>
</rss>
