Skip to content

Archive / page 89

All articles

Every practical article from the Nalar archive, newest first.

Python 01 Sep 2026 4 min read

Python Context Managers for Reliable Resource Cleanup

Python’s with statement is more than convenient file syntax. It is a general protocol for pairing setup with guaranteed cleanup, including when code exits early or raises an exception. Understanding context managers makes resource lifetimes visible and prevents a broad class of leaked files, locks, connections, and temporary state. Why try/finally is the foundation Without a context manager, safe cleanup often looks like this: file = open("input.txt", encoding="utf-8") try: data = file.read() finally: file.close() The finally block runs whether the read succeeds or raises. A with statement packages that pattern:

Cloud Computing 01 Sep 2026 4 min read

Propagate Timeout Budgets Across Cloud Services

A request that crosses several cloud services does not have one timeout. It has a chain of deadlines: client, edge proxy, application, database, and downstream APIs. When those limits are configured independently, an upstream service can give up while downstream work continues consuming connections and CPU for a response nobody will use. An end-to-end timeout budget gives the request one bounded lifetime and lets each hop consume part of it.

Web Development 01 Sep 2026 5 min read

Progressive Enhancement for Resilient Web Forms

A web form does not need JavaScript to submit data. That native capability is a useful reliability baseline. Progressive enhancement starts with semantic HTML and a server endpoint that can complete the operation, then adds JavaScript for faster feedback or richer interactions. If the enhancement fails, the core task still has a path to succeed. This approach is valuable even in highly interactive applications because JavaScript can fail for ordinary reasons: slow networks, stale cached chunks, browser extensions, runtime exceptions, or a partial deployment.

Data Science 01 Sep 2026 5 min read

Probability Calibration for Classification Models

A classifier can rank examples correctly while producing probabilities that are poor estimates of real-world likelihood. If a model assigns 0.8 probability to many comparable cases, calibration asks whether roughly 80% of those cases are actually positive. This matters whenever probabilities drive decisions such as pricing, triage, alert thresholds, expected value, or human review. Discrimination and calibration are different Metrics such as ROC AUC evaluate how well a model ranks positive examples above negative ones. They do not require predicted probabilities to match observed frequencies.

Web Development 01 Sep 2026 5 min read

Preventing SSRF in Backend Services That Fetch User-Supplied URLs

Features that fetch a URL supplied by a user appear in webhook testers, image importers, link previewers, document converters, and integration platforms. They also create a server-side request forgery (SSRF) boundary: an attacker can try to make the backend send requests to destinations the attacker cannot reach directly. A secure design needs more than a blacklist of suspicious strings. Understand the trust boundary The dangerous capability is not URL parsing itself. It is allowing untrusted input to influence a network connection made with the server’s network identity.

Cybersecurity 01 Sep 2026 3 min read

Prevent Session Fixation During Web Authentication

Session fixation occurs when an attacker can cause a victim to authenticate while using a session identifier the attacker already knows. If the application keeps that identifier after login, the attacker may reuse it to access the newly authenticated session. The core defense is to change the session identifier whenever privilege changes. Rotate at authentication boundaries After credentials, passkeys, or another authentication factor succeeds, create a fresh unpredictable session identifier and retire the pre-authentication identifier. Apply the same principle after privilege elevation, impersonation boundaries, or other security-sensitive identity changes.

Go 01 Sep 2026 2 min read

Preserve Cancellation Causes with context.WithCancelCause in Go

Go’s context.Context propagates deadlines and cancellation across API boundaries. Traditional cancellation tells downstream work that it should stop, but ctx.Err() only reports context.Canceled or context.DeadlineExceeded. Sometimes the reason matters. Go 1.20 introduced context.WithCancelCause, and later releases added cause-aware deadline helpers. They preserve a domain error without changing normal cancellation behavior. Attach a cause to cancellation package main import ( "context" "errors" "fmt" ) var ErrSuperseded = errors.New("request superseded") func main() { ctx, cancel := context.WithCancelCause(context.Background()) cancel(ErrSuperseded) fmt.Println(ctx.Err()) // context canceled fmt.Println(context.Cause(ctx)) // request superseded } Code that only understands Context still sees ordinary cancellation. Code that needs diagnostic detail can call context.Cause.

Cybersecurity 01 Sep 2026 5 min read

Practical Threat Modeling with Trust Boundaries and Abuse Cases

Threat modeling is most useful before a vulnerability becomes a patch request. It gives a team a structured way to ask how a system can be misused, which assumptions are security-sensitive, and where defenses should exist. A useful threat model does not need to be a large document. For many services, a one-page data-flow sketch plus a prioritized set of abuse cases is enough to improve design decisions. Begin with assets and security goals Start by identifying what the system is trying to protect.

Rust 01 Sep 2026 5 min read

Practical Error Handling in Rust with Result and the ? Operator

Rust makes recoverable failure part of a function’s type. Instead of relying on exceptions, operations that can fail commonly return Result<T, E>, forcing callers to either handle the error or propagate it. That explicitness can feel verbose at first. The ? operator and well-designed error types keep the code concise without hiding failure paths. Result represents success or failure Result<T, E> has two variants: Ok(value) Err(error) Reading a file therefore returns either the file contents or an I/O error:

Web Development 01 Sep 2026 6 min read

Liveness and Readiness Health Checks for Backend Services

Health endpoints look simple, but their semantics directly affect how a production platform routes traffic and restarts applications. A poorly designed check can turn a temporary database slowdown into a restart loop or send requests to an instance that has not finished initializing. The most useful model separates two questions: Liveness: Is this process still capable of running? Readiness: Should this instance receive new traffic right now? Those questions sound similar, but they should usually have different answers and different failure behavior.

Linux 01 Sep 2026 5 min read

Linux Network Troubleshooting with ip, ss, dig, and curl

When a Linux service is “unreachable,” the failure can be in several different layers: the local interface, routing, a listening socket, DNS, a firewall, TLS, or the application itself. Randomly restarting services makes diagnosis harder. A better approach is to move from local state outward and identify the first layer that does not behave as expected. 1. Confirm the interface and address Start with the addresses configured on the host:

Web Development 01 Sep 2026 7 min read

Keyset Pagination in SQL for Fast, Stable APIs

Pagination looks simple until a table becomes large or new rows are inserted while a client is paging through results. LIMIT and OFFSET are easy to understand, but deep offsets can become expensive and changing data can make rows appear twice or disappear between requests. Keyset pagination, also called seek pagination, avoids those problems by asking for rows after a known position instead of asking the database to skip a number of rows.

Database 01 Sep 2026 4 min read

Keyset Pagination for Stable and Efficient Database Queries

Pagination looks straightforward with LIMIT and OFFSET, but deep offsets become increasingly expensive and can produce unstable results when rows are inserted or deleted between requests. Keyset pagination, also called seek pagination, uses the last seen sort key as the starting point for the next query. Why OFFSET degrades A typical query is: SELECT id, created_at, title FROM posts ORDER BY created_at DESC LIMIT 50 OFFSET 100000; The database still has to find and skip preceding rows before returning the page. There is also a correctness problem: if a new row is inserted at the front between requests, offsets shift and a user may see a duplicate or miss an item.

Cloud Computing 01 Sep 2026 5 min read

Idempotent Event Consumers for At-Least-Once Delivery

Many queues and event brokers provide at-least-once delivery: a message that has been accepted can be delivered again when acknowledgements are lost, consumers crash, visibility timeouts expire, or the broker retries after uncertain outcomes. Duplicates are therefore not exceptional. A robust consumer should assume that the same logical event can arrive more than once. Why duplicates happen Consider this sequence: a consumer receives an event; it updates the database successfully; the process crashes before acknowledging the message; the broker makes the message visible again; another consumer receives it. The broker cannot know that the database update happened. Redelivery is the safer choice.

Web Development 01 Sep 2026 8 min read

Idempotency Keys for Safe API Retries

Retries are essential in distributed systems. Networks fail, clients time out, load balancers reset connections, and responses sometimes disappear after a server has already committed a write. The dangerous case is a retry of a non-idempotent operation. If a client sends POST /orders, times out, and sends the same request again, the server may create two orders even though the user intended one. An idempotency key gives the client a stable identifier for one logical operation. The server remembers the result associated with that key and can return the same result when the request is retried.

Web Development 01 Sep 2026 4 min read

HTTP Conditional Requests with ETag and Last-Modified

HTTP caching is not only about choosing a long max-age. Applications often need clients to revalidate data because a resource can change, while still avoiding retransmitting the full representation when it has not changed. HTTP validators solve that problem. The two common validators are ETag and Last-Modified. Freshness and validation are different A freshness directive can tell a cache that a response may be reused without contacting the server for a period:

Linux 01 Sep 2026 5 min read

Harden systemd Services with Security Directives

A systemd unit can do more than start and restart a process. It can also define a security boundary around the service by restricting filesystem access, Linux capabilities, namespaces, privilege changes, and resource consumption. These controls do not replace application security, but they can reduce the damage caused by a compromised or misbehaving process. Start from the service’s real requirements Hardening works best when it is based on what the process actually needs.

Go 01 Sep 2026 7 min read

Graceful HTTP Server Shutdown in Go

Stopping a web server with Ctrl+C 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. Go’s standard library already provides the pieces needed for a clean shutdown. The main tools are os/signal, context, and http.Server.Shutdown. This guide shows a practical pattern for shutting down an HTTP server when the process receives SIGINT or SIGTERM.

Go 01 Sep 2026 4 min read

Go Error Wrapping with errors.Is and errors.As

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. Error strings are a fragile interface 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:

Go 01 Sep 2026 8 min read

Go Context Timeouts and Request Cancellation

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. Go solves this with context.Context. Every incoming *http.Request 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.

Linux 01 Sep 2026 4 min read

Find Hidden Linux Disk Usage with df, du, and lsof

A Linux filesystem can report 95% usage in df while du appears to account for much less. The tools are not contradicting each other: they measure different things. df asks the filesystem about allocated blocks. du walks visible directory entries and sums blocks reachable through those paths. The gap between those views points to several useful troubleshooting cases. Start with the filesystem view Check filesystems and their types: df -hT Identify the mount that is actually full. Do not immediately scan recursively from /; container mounts, network filesystems, and bind mounts can make that slow and misleading.

Web Development 01 Sep 2026 5 min read

Feature Flags Without Long-Lived Technical Debt

Feature flags decouple code deployment from feature release. A team can deploy dormant code, enable it for internal users, roll it out gradually, and disable it without rebuilding the application. The cost is hidden control flow. Every long-lived flag creates another possible system configuration, and interacting flags multiply those configurations quickly. The engineering goal is therefore not “use flags everywhere.” It is to make each flag temporary, observable, and owned.

Go 01 Sep 2026 6 min read

Exponential Backoff with Jitter in Go

Retries can make distributed systems more resilient, but immediate retries can also make an outage worse. If thousands of clients retry at the same moment, a recovering dependency receives another synchronized burst of traffic before it has time to stabilize. A common solution is exponential backoff with jitter: increase the maximum delay after each failure, then randomize the actual wait. This article builds that pattern with Go’s standard library and shows where retry logic belongs—and where it does not.

Software Engineering 01 Sep 2026 5 min read

Evolving APIs Without Breaking Clients

An API is not only an HTTP path or function signature. It is a contract about syntax, semantics, timing, errors, ordering, defaults, and lifecycle. Breaking changes often happen because a server remains syntactically compatible while changing one of those less-visible assumptions. Safe API evolution starts by identifying what clients can reasonably depend on and designing changes that allow old and new versions to coexist. Compatibility has multiple dimensions A change can preserve JSON shape and still break clients.