<?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: Ali Haider</title>
    <description>The latest articles on DEV Community by Ali Haider (@alihaider8014).</description>
    <link>https://dev.to/alihaider8014</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3852313%2F4bc86982-f568-45cf-8015-8c22430707d3.jpeg</url>
      <title>DEV Community: Ali Haider</title>
      <link>https://dev.to/alihaider8014</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alihaider8014"/>
    <language>en</language>
    <item>
      <title>Building a Scalable Audit &amp; System Logging Architecture for Healthcare Applications</title>
      <dc:creator>Ali Haider</dc:creator>
      <pubDate>Thu, 22 Oct 2026 14:02:30 +0000</pubDate>
      <link>https://dev.to/alihaider8014/building-a-scalable-audit-system-logging-architecture-for-healthcare-applications-1n8g</link>
      <guid>https://dev.to/alihaider8014/building-a-scalable-audit-system-logging-architecture-for-healthcare-applications-1n8g</guid>
      <description>&lt;p&gt;&lt;em&gt;A practical approach to separating business audit events from technical system logs for better debugging, observability, and accountability.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When people think about healthcare software, they usually think about Electronic Health Records (EHRs), appointment scheduling, billing systems, prescriptions, or patient portals.&lt;/p&gt;

&lt;p&gt;Those features are obviously important—but after several years working on backend systems, I've learned that one of the most valuable components isn't visible to users at all.&lt;/p&gt;

&lt;p&gt;It's &lt;strong&gt;logging&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Users don't notice it.&lt;/p&gt;

&lt;p&gt;Product demos rarely mention it.&lt;/p&gt;

&lt;p&gt;But the moment something goes wrong in production, it becomes one of the first places every engineer looks.&lt;/p&gt;

&lt;p&gt;Questions like these suddenly become critical:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why did this request fail?&lt;/li&gt;
&lt;li&gt;Who updated this record?&lt;/li&gt;
&lt;li&gt;What changed?&lt;/li&gt;
&lt;li&gt;Was it a system issue or a user action?&lt;/li&gt;
&lt;li&gt;When did it happen?&lt;/li&gt;
&lt;li&gt;Can we reproduce it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without a well-designed logging strategy, answering those questions often means digging through databases, reproducing issues, or relying on guesswork.&lt;/p&gt;

&lt;p&gt;With a good logging architecture, the answers are usually only a few searches away.&lt;/p&gt;

&lt;p&gt;In this article, I'd like to share a logging architecture pattern that separates Audit Logs from System Logs, why that distinction matters, and some practical lessons I've learned while designing enterprise backend applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Logging Matters in Healthcare
&lt;/h2&gt;

&lt;p&gt;Healthcare applications manage some of the most sensitive information in any industry.&lt;/p&gt;

&lt;p&gt;Every day, systems perform operations like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Updating patient demographics&lt;/li&gt;
&lt;li&gt;Scheduling appointments&lt;/li&gt;
&lt;li&gt;Recording medications&lt;/li&gt;
&lt;li&gt;Signing clinical encounters&lt;/li&gt;
&lt;li&gt;Updating insurance information&lt;/li&gt;
&lt;li&gt;Managing laboratory results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each operation changes business data that someone may need to investigate later.&lt;/p&gt;

&lt;p&gt;Imagine receiving a production ticket that simply says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The patient's insurance information changed yesterday.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first question isn't **how **to fix it.&lt;/p&gt;

&lt;p&gt;The first question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What actually happened?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A good logging strategy should make that easy to answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit Logs vs. System Logs
&lt;/h2&gt;

&lt;p&gt;One of the biggest mistakes I see is treating audit logs and system logs as the same thing.&lt;/p&gt;

&lt;p&gt;Although both record events, they solve completely different problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Audit Logs&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Record business events&lt;/li&gt;
&lt;li&gt;Who changed the data?&lt;/li&gt;
&lt;li&gt;Business accountability
&lt;/li&gt;
&lt;li&gt;User activity&lt;/li&gt;
&lt;li&gt;Compliance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;System Logs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Record technical events&lt;/li&gt;
&lt;li&gt;How did the application behave?&lt;/li&gt;
&lt;li&gt;Technical troubleshooting&lt;/li&gt;
&lt;li&gt;Request lifecycle&lt;/li&gt;
&lt;li&gt;Performance &amp;amp; debugging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Audit Logs tell the story of the business.&lt;/li&gt;
&lt;li&gt;System Logs tell the story of the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping these responsibilities separate makes both systems much easier to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-Level Architecture
&lt;/h2&gt;

&lt;p&gt;Instead of allowing every controller or service to generate logs independently, one common approach is to centralize the logging process.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                Client

                  │

                  ▼

        HTTP Request Received

                  │

                  ▼

     Request Processing Layer

      ┌────────────┴────────────┐

      ▼                         ▼

System Logging           Business Logic

                                  │

                                  ▼

                    Audit Event Dispatcher

                                  │

               ┌──────────────────┼──────────────────┐

               ▼                  ▼                  ▼

         Domain A           Domain B           Domain C

               └──────────────────┼──────────────────┘

                                  ▼

                 Search &amp;amp; Analytics Platform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This separation keeps business logic focused on business problems while allowing logging to evolve independently.&lt;/p&gt;

&lt;h2&gt;
  
  
  System Logging
&lt;/h2&gt;

&lt;p&gt;System logs describe how the application behaves.&lt;/p&gt;

&lt;p&gt;Every incoming request typically generates a system log regardless of whether business data changes.&lt;/p&gt;

&lt;p&gt;Typical metadata includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP Method&lt;/li&gt;
&lt;li&gt;Endpoint&lt;/li&gt;
&lt;li&gt;Authenticated User&lt;/li&gt;
&lt;li&gt;Organization ID&lt;/li&gt;
&lt;li&gt;Client IP&lt;/li&gt;
&lt;li&gt;Timestamp&lt;/li&gt;
&lt;li&gt;Request ID / Correlation ID&lt;/li&gt;
&lt;li&gt;Request Parameters&lt;/li&gt;
&lt;li&gt;Response Status&lt;/li&gt;
&lt;li&gt;Execution Time&lt;/li&gt;
&lt;li&gt;Exception Details&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simplified pipeline looks like this:&lt;/p&gt;

&lt;p&gt;Incoming Request &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Collect Request Metadata &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Execute Business Logic &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Capture Response &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Generate System Log &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Search Platform&lt;/p&gt;

&lt;p&gt;Capturing request metadata before executing business logic is especially valuable.&lt;/p&gt;

&lt;p&gt;Even if an exception occurs later, engineers still have enough context to investigate what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit Logging
&lt;/h2&gt;

&lt;p&gt;Audit logging has a different purpose.&lt;/p&gt;

&lt;p&gt;Not every request deserves an audit event.&lt;/p&gt;

&lt;p&gt;Viewing a dashboard usually doesn't.&lt;/p&gt;

&lt;p&gt;Updating a patient record probably does.&lt;/p&gt;

&lt;p&gt;Instead of placing audit logic throughout the application, a centralized dispatcher can determine whether an action should generate an audit event.&lt;/p&gt;

&lt;p&gt;A simplified flow looks like this.&lt;/p&gt;

&lt;p&gt;Business Operation &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Audit Dispatcher &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Determine Business Domain &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Module A/B/C &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Compare Previous State &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Generate Audit Event &lt;strong&gt;--&amp;gt;&lt;/strong&gt; Store Event&lt;/p&gt;

&lt;p&gt;Each module owns only the logic related to its own domain.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Record&lt;/li&gt;
&lt;li&gt;Update Record&lt;/li&gt;
&lt;li&gt;Delete Record&lt;/li&gt;
&lt;li&gt;Restore Record&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps the architecture modular and avoids duplicating logging logic across multiple controllers or services.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing a Search Platform
&lt;/h2&gt;

&lt;p&gt;As applications grow, log volume increases rapidly.&lt;/p&gt;

&lt;p&gt;Searching millions of log entries using relational databases alone can become inefficient.&lt;/p&gt;

&lt;p&gt;Search and analytics platforms such as Elasticsearch, OpenSearch, or similar technologies are designed specifically for this workload.&lt;/p&gt;

&lt;p&gt;Benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full-text search&lt;/li&gt;
&lt;li&gt;Fast filtering&lt;/li&gt;
&lt;li&gt;Near real-time indexing&lt;/li&gt;
&lt;li&gt;Time-based queries&lt;/li&gt;
&lt;li&gt;Aggregations&lt;/li&gt;
&lt;li&gt;Dashboards&lt;/li&gt;
&lt;li&gt;Scalable storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of storing logs alongside transactional data, indexing them separately makes production investigations significantly faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Separating Audit &amp;amp; System Logs
&lt;/h2&gt;

&lt;p&gt;After adopting this architecture, organizations often notice several practical improvements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Faster Debugging
&lt;/h3&gt;

&lt;p&gt;Engineers spend less time reproducing issues because request history is already available.&lt;/p&gt;

&lt;h3&gt;
  
  
  Better Accountability
&lt;/h3&gt;

&lt;p&gt;Business actions become traceable.&lt;/p&gt;

&lt;p&gt;Teams can understand who performed an action, what changed, and when it happened.&lt;/p&gt;

&lt;h3&gt;
  
  
  Easier Production Support
&lt;/h3&gt;

&lt;p&gt;Support teams can investigate incidents without involving developers in every case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improved Observability
&lt;/h3&gt;

&lt;p&gt;System logs provide visibility into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API failures&lt;/li&gt;
&lt;li&gt;Background jobs&lt;/li&gt;
&lt;li&gt;Integration issues&lt;/li&gt;
&lt;li&gt;Slow requests&lt;/li&gt;
&lt;li&gt;Exceptions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cleaner Architecture
&lt;/h3&gt;

&lt;p&gt;Business logic remains focused on business functionality instead of logging implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Considerations
&lt;/h2&gt;

&lt;p&gt;Logging should improve observability—not reduce application performance.&lt;/p&gt;

&lt;p&gt;Some practices that have worked well include:&lt;/p&gt;

&lt;p&gt;Log meaningful business events.&lt;/p&gt;

&lt;p&gt;Avoid storing sensitive information.&lt;/p&gt;

&lt;p&gt;Keep payloads concise.&lt;/p&gt;

&lt;p&gt;Index commonly searched fields.&lt;/p&gt;

&lt;p&gt;Rotate or archive old logs.&lt;/p&gt;

&lt;p&gt;Consider asynchronous logging for high-volume systems.&lt;/p&gt;

&lt;p&gt;Good logging should be informative without becoming expensive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Logging Mistakes
&lt;/h2&gt;

&lt;p&gt;Some mistakes appear repeatedly across enterprise applications.&lt;/p&gt;

&lt;p&gt;❌ Mixing audit logs with system logs.&lt;/p&gt;

&lt;p&gt;❌ Logging passwords or authentication tokens.&lt;/p&gt;

&lt;p&gt;❌ Logging every single request without a purpose.&lt;/p&gt;

&lt;p&gt;❌ Making logs impossible to search.&lt;/p&gt;

&lt;p&gt;❌ Ignoring retention and archival strategies.&lt;/p&gt;

&lt;p&gt;A thoughtful logging strategy is just as important as the logging technology itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;p&gt;One lesson has stayed with me throughout multiple backend projects:&lt;/p&gt;

&lt;p&gt;Logging should never be treated as something you add after a feature is finished.&lt;/p&gt;

&lt;p&gt;It should be part of the system architecture from the beginning.&lt;/p&gt;

&lt;p&gt;Good logging doesn't only help developers.&lt;/p&gt;

&lt;p&gt;It helps support engineers.&lt;/p&gt;

&lt;p&gt;It helps administrators.&lt;/p&gt;

&lt;p&gt;It helps operations teams.&lt;/p&gt;

&lt;p&gt;And ultimately, it improves confidence in the software itself.&lt;/p&gt;

&lt;p&gt;Looking ahead, I also think AI will change how we interact with logs.&lt;/p&gt;

&lt;p&gt;Instead of manually searching thousands of entries, AI systems will be able to summarize incidents, identify unusual behavior, explain failures in natural language, and assist engineers during production investigations.&lt;/p&gt;

&lt;p&gt;For healthcare systems, where reliability and accountability are essential, that evolution is particularly exciting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Logging isn't the feature users ask for.&lt;/p&gt;

&lt;p&gt;It's the feature engineers appreciate when everything else goes wrong.&lt;/p&gt;

&lt;p&gt;Separating &lt;strong&gt;Audit Logs&lt;/strong&gt; from &lt;strong&gt;System Logs&lt;/strong&gt; creates a cleaner architecture, simplifies troubleshooting, and improves long-term maintainability.&lt;/p&gt;

&lt;p&gt;Whether you're building healthcare software, SaaS products, or enterprise platforms, investing in a thoughtful logging strategy will pay dividends long after the feature has shipped.&lt;/p&gt;

&lt;p&gt;Because in production systems, understanding &lt;strong&gt;what happened&lt;/strong&gt; is often just as important as making sure it never happens again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discussion
&lt;/h2&gt;

&lt;p&gt;How do you approach logging in your applications?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do you separate audit logs from system logs?&lt;/li&gt;
&lt;li&gt;Have you adopted centralized logging?&lt;/li&gt;
&lt;li&gt;Which search platform are you using—Elasticsearch, OpenSearch, Loki, Splunk, or something else?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'd love to hear how other teams are solving these challenges.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>elasticsearch</category>
      <category>backend</category>
    </item>
    <item>
      <title>🚨 PHP developers: Check your production PHP version. A critical security update is out.</title>
      <dc:creator>Ali Haider</dc:creator>
      <pubDate>Thu, 22 Oct 2026 13:09:09 +0000</pubDate>
      <link>https://dev.to/alihaider8014/php-developers-check-your-production-php-version-a-critical-security-update-is-out-3o12</link>
      <guid>https://dev.to/alihaider8014/php-developers-check-your-production-php-version-a-critical-security-update-is-out-3o12</guid>
      <description>&lt;p&gt;On October 21, the PHP team released security updates for PHP 8.5, 8.4, 8.3 and 8.2.&lt;/p&gt;

&lt;p&gt;The patched versions are:&lt;/p&gt;

&lt;p&gt;🔹 PHP 8.5.12&lt;br&gt;&lt;br&gt;
🔹 PHP 8.4.27&lt;br&gt;&lt;br&gt;
🔹 PHP 8.3.36&lt;br&gt;&lt;br&gt;
🔹 PHP 8.2.35  &lt;/p&gt;

&lt;p&gt;These releases address two critical vulnerabilities:&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;CVE-2026-109618&lt;/strong&gt; — related to out-of-memory handling&lt;br&gt;&lt;br&gt;
• &lt;strong&gt;CVE-2026-109619&lt;/strong&gt; — related to stale internal state  &lt;/p&gt;

&lt;p&gt;Both can potentially lead to remote code execution without authentication. That means the issue isn't limited to application-level bugs.&lt;/p&gt;

&lt;p&gt;Here's what I'd check as a backend engineer:&lt;/p&gt;

&lt;p&gt;✅ Identify the PHP versions running across production servers, containers and CI/CD environments.&lt;/p&gt;

&lt;p&gt;✅ Check whether your hosting provider or Linux distribution has supplied patched packages.&lt;/p&gt;

&lt;p&gt;✅ Update to a fixed version and restart PHP workers or services where required.&lt;/p&gt;

&lt;p&gt;✅ Verify the running version after deployment.&lt;/p&gt;

&lt;p&gt;✅ Review your upgrade plan if you're still using an unsupported PHP branch.&lt;/p&gt;

&lt;p&gt;One more important detail: &lt;strong&gt;PHP 8.2 reaches end of life on December 31, 2026&lt;/strong&gt;, so teams using it should also plan their next upgrade.&lt;/p&gt;

&lt;p&gt;Modern frameworks, clean architecture and automated tests are important—but keeping the underlying runtime secure is equally important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When was the last time you checked the PHP version running in your production environment?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Official advisory: &lt;a href="https://www.php.net/archive/2026.php#2026-10-21-5" rel="noopener noreferrer"&gt;https://www.php.net/archive/2026.php#2026-10-21-5&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>Stop Optimizing the Wrong Things: Practical Database Optimization Techniques Every Backend Developer Should Know</title>
      <dc:creator>Ali Haider</dc:creator>
      <pubDate>Mon, 03 Aug 2026 19:30:08 +0000</pubDate>
      <link>https://dev.to/alihaider8014/stop-optimizing-the-wrong-things-practical-database-optimization-techniques-every-backend-4p7j</link>
      <guid>https://dev.to/alihaider8014/stop-optimizing-the-wrong-things-practical-database-optimization-techniques-every-backend-4p7j</guid>
      <description>&lt;p&gt;We've all been there.&lt;/p&gt;

&lt;p&gt;An API that used to respond in milliseconds suddenly becomes slower as the database grows. The application logic hasn't changed much, but performance keeps degrading.&lt;/p&gt;

&lt;p&gt;In many cases, the problem isn't the framework or the programming language—it's how we're interacting with the database.&lt;/p&gt;

&lt;p&gt;This article shares a few practical optimization techniques I've used while working on backend systems. These aren't advanced tricks; they're small improvements that can make a noticeable difference in production environments.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Don't Apply Functions to Indexed Columns
&lt;/h2&gt;

&lt;p&gt;Imagine you have an indexed column named &lt;code&gt;updated&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A common approach is filtering records like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nb"&gt;DATE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'2026-07-30'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although it works, there's a hidden cost.&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;updated&lt;/code&gt; is wrapped inside a function, the database usually can't use the index efficiently. Instead of performing an index range scan, it may need to evaluate every row.&lt;/p&gt;

&lt;p&gt;A better approach is to compare the raw timestamp:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="s1"&gt;'2026-07-30 00:00:00'&lt;/span&gt;
&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="s1"&gt;'2026-07-31 00:00:00'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows the database optimizer to use the index effectively.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Convert Input Instead of Every Database Row
&lt;/h2&gt;

&lt;p&gt;I recently reviewed code that converted every timestamp inside SQL using time zone functions.&lt;/p&gt;

&lt;p&gt;While technically correct, it forced the database to perform a conversion for every matching row.&lt;/p&gt;

&lt;p&gt;Instead, convert the user's input once in your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$fromLocal&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setTimezone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DateTimeZone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'UTC'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then execute a simple query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;updated&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is easier to read, more maintainable, and usually much faster.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Don't Load Thousands of Rows Just to Count Them
&lt;/h2&gt;

&lt;p&gt;I've seen code similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$Model&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$sql&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, but think about what's happening.&lt;/p&gt;

&lt;p&gt;The database sends every matching row to your application.&lt;/p&gt;

&lt;p&gt;Your application allocates memory for every record.&lt;/p&gt;

&lt;p&gt;Finally, PHP counts the array.&lt;/p&gt;

&lt;p&gt;If the query returns 200,000 rows, you've transferred and stored 200,000 records simply to obtain a number.&lt;/p&gt;

&lt;p&gt;Instead, let the database do the counting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, if you're wrapping an existing query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database returns a single integer instead of thousands of records.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Write Queries That Scale
&lt;/h2&gt;

&lt;p&gt;A query that performs well with 500 rows may become a bottleneck when your database reaches millions of records.&lt;/p&gt;

&lt;p&gt;Whenever you review a query, ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can this use an index?&lt;/li&gt;
&lt;li&gt;Am I processing unnecessary data?&lt;/li&gt;
&lt;li&gt;Can the database perform this operation more efficiently than my application?&lt;/li&gt;
&lt;li&gt;Am I transferring more data than I actually need?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions often reveal opportunities for optimization.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Readability Is Also an Optimization
&lt;/h2&gt;

&lt;p&gt;Performance isn't the only goal.&lt;/p&gt;

&lt;p&gt;Code that is easy to understand is easier to maintain, debug, and improve.&lt;/p&gt;

&lt;p&gt;For example, converting user input once in the application layer is often simpler than embedding multiple conditional time zone conversions inside SQL.&lt;/p&gt;

&lt;p&gt;Future developers—including your future self—will thank you.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Database optimization doesn't always require rewriting your architecture.&lt;/p&gt;

&lt;p&gt;Often, the biggest gains come from small improvements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid wrapping indexed columns in functions.&lt;/li&gt;
&lt;li&gt;Convert user input instead of every database row.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;COUNT(*)&lt;/code&gt; when you only need totals.&lt;/li&gt;
&lt;li&gt;Return only the data you actually need.&lt;/li&gt;
&lt;li&gt;Think about how the database executes your query—not just whether the query works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As your application grows, these habits become increasingly valuable. Small optimizations applied to frequently executed queries can have a meaningful impact on performance, resource usage, and overall scalability.&lt;/p&gt;

&lt;p&gt;What optimization technique has had the biggest impact on your applications? I'd love to hear your experiences in the comments.&lt;/p&gt;

</description>
      <category>database</category>
      <category>queryoptimization</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>Flexible Boolean Validation for Laravel APIs — Handling “true”/“false” Strings Without the Headache</title>
      <dc:creator>Ali Haider</dc:creator>
      <pubDate>Mon, 30 Mar 2026 20:52:18 +0000</pubDate>
      <link>https://dev.to/alihaider8014/flexible-boolean-validation-for-laravel-2oad</link>
      <guid>https://dev.to/alihaider8014/flexible-boolean-validation-for-laravel-2oad</guid>
      <description>&lt;p&gt;Every Laravel developer has hit this at some point.&lt;/p&gt;

&lt;p&gt;You’re working on a clean API. Everything looks good. Then suddenly validation fails because the frontend sent "true" instead of true.&lt;/p&gt;

&lt;p&gt;Laravel’s default boolean rule is excellent for strictness, but it rejects common string values like "true" and "false" that come from JavaScript, React/Vue forms, query strings, or external services.&lt;/p&gt;

&lt;p&gt;The result? Scattered filter_var() calls, custom rules, or manual casting — repeated across every project.&lt;/p&gt;

&lt;p&gt;I got tired of the same workaround and decided to fix it once and for all.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introducing flexible-boolean&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I built a small, focused package that extends Laravel’s boolean validation to support real-world API inputs while keeping everything clean and secure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supported values now include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"true" / "false" (strings)&lt;/li&gt;
&lt;li&gt;1 / 0&lt;/li&gt;
&lt;li&gt;Native true / false&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It integrates seamlessly with Laravel’s validation system — no side effects, no performance hit.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Quick Example&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Install via Composer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require alihaider/flexible-boolean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use it in your Form Requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&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="s1"&gt;'is_active'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'boolean:flexible'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="s1"&gt;'newsletter'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FlexibleBooleanRule&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="s1"&gt;'is_published'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'boolean'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// still works as before&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;You can also register the rule globally if you prefer.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Before vs After&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;: Random 422 errors + extra controller logic&lt;br&gt;
&lt;strong&gt;After&lt;/strong&gt;: Predictable validation that just works with frontend data&lt;br&gt;
It’s a tiny package, but it saves a surprising amount of debugging time when building production APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let’s Discuss&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;How are you handling boolean values from the frontend in your Laravel projects today?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manual casting?&lt;/li&gt;
&lt;li&gt;Custom rules per project?&lt;/li&gt;
&lt;li&gt;Something else entirely?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drop your preferred approach in the comments — I’m curious to see the different solutions the community uses.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Package&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://packagist.org/packages/alihaider/flexible-boolean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you found this useful, give it a like or save it for later. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>laravel</category>
      <category>api</category>
    </item>
  </channel>
</rss>
