<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Backend on Nalar</title>
    <link>https://nalar.dev/tags/backend/</link>
    <description>Recent content in Backend on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 01 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/backend/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Atomic File Writes in Go: Prevent Partial and Corrupted Files</title>
      <link>https://nalar.dev/atomic-file-writes-in-go/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/atomic-file-writes-in-go/</guid>
      <description>&lt;p&gt;Writing a file with &lt;code&gt;os.WriteFile&lt;/code&gt; is simple, but it is not always the safest choice for configuration files, generated metadata, caches, state files, or other data that must never be left half-written.&lt;/p&gt;&#xA;&lt;p&gt;If a process crashes or the machine loses power while a file is being replaced, readers may observe incomplete content. A common way to reduce this risk is an &lt;strong&gt;atomic file write&lt;/strong&gt;: write the new content to a temporary file first, then replace the destination with a rename.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Go Context Timeouts and Request Cancellation</title>
      <link>https://nalar.dev/go-context-timeouts-and-request-cancellation/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/go-context-timeouts-and-request-cancellation/</guid>
      <description>&lt;p&gt;A Go HTTP handler can outlive the request that started it unless the work inside the handler pays attention to cancellation. That matters when a client disconnects, an upstream request takes too long, or a database query is no longer useful.&lt;/p&gt;&#xA;&lt;p&gt;Go solves this with &lt;code&gt;context.Context&lt;/code&gt;. Every incoming &lt;code&gt;*http.Request&lt;/code&gt; already has a context, and that context is canceled when the client connection closes, the request is canceled by HTTP/2, or the handler returns. You can also derive a shorter deadline for work that should not consume the entire request lifetime.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Go Error Wrapping with errors.Is and errors.As</title>
      <link>https://nalar.dev/go-error-wrapping-errors-is-errors-as/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/go-error-wrapping-errors-is-errors-as/</guid>
      <description>&lt;p&gt;Errors often cross several layers of a Go application. A low-level function may know that a file is missing, while a higher-level function needs to add context about which operation failed. Go error wrapping lets you add that context without losing information callers need for reliable handling.&lt;/p&gt;&#xA;&lt;h2 id=&#34;why-error-strings-are-fragile&#34;&gt;Why error strings are fragile&lt;/h2&gt;&#xA;&lt;p&gt;Do not make program logic depend on error wording. Adding a filename or changing punctuation can break string comparisons even when the underlying condition is unchanged. Prefer semantic checks:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Graceful HTTP Server Shutdown in Go</title>
      <link>https://nalar.dev/graceful-http-server-shutdown-in-go/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/graceful-http-server-shutdown-in-go/</guid>
      <description>&lt;p&gt;Stopping a web server with &lt;code&gt;Ctrl+C&lt;/code&gt; looks harmless during development, but production deployments need a more careful shutdown process. If a process exits immediately, active HTTP requests can be interrupted, clients may receive connection errors, and in-flight work can be left unfinished.&lt;/p&gt;&#xA;&lt;p&gt;Go&amp;rsquo;s standard library already provides the pieces needed for a clean shutdown. The main tools are &lt;code&gt;os/signal&lt;/code&gt;, &lt;code&gt;context&lt;/code&gt;, and &lt;code&gt;http.Server.Shutdown&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This guide shows a practical pattern for shutting down an HTTP server when the process receives &lt;code&gt;SIGINT&lt;/code&gt; or &lt;code&gt;SIGTERM&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Request Coalescing in Go Without Extra Dependencies</title>
      <link>https://nalar.dev/request-coalescing-in-go/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/request-coalescing-in-go/</guid>
      <description>&lt;p&gt;When many requests ask for the same expensive resource at the same time, running identical work for every caller can overload a database, API, or filesystem. A cache can help after a result exists, but it does not necessarily prevent several concurrent cache misses from triggering the same backend operation.&lt;/p&gt;&#xA;&lt;p&gt;Request coalescing solves a different problem: while one operation for a key is already running, later callers wait for that operation and share its result. After the operation finishes, the result is forgotten. The next request starts fresh work.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Testing Go HTTP Handlers with httptest</title>
      <link>https://nalar.dev/testing-go-http-handlers-with-httptest/</link>
      <pubDate>Tue, 01 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/testing-go-http-handlers-with-httptest/</guid>
      <description>&lt;p&gt;HTTP handlers are one of the easiest parts of a Go service to test well. You usually do not need to bind a real network port, start the entire application, or depend on an external test framework.&lt;/p&gt;&#xA;&lt;p&gt;Go&amp;rsquo;s standard library provides &lt;code&gt;net/http/httptest&lt;/code&gt;, which can construct HTTP requests, capture handler responses, and even start temporary HTTP servers when a real client-server round trip matters.&lt;/p&gt;&#xA;&lt;p&gt;This guide builds a small JSON endpoint and tests it at several useful levels.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
