Skip to main content

Posts

Showing posts with the label Backend

Troubleshooting MongoDB 'Sort Exceeded Memory Limit' Without allowDiskUse

  You have likely encountered this error in your logs, usually causing a 500 status code on a production endpoint: Error Code 16819:  Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. The immediate reaction is often to add  { allowDiskUse: true }  to the aggregation options. While this eliminates the error, it is a performance patch, not a fix. It forces MongoDB to spill the data into temporary files on the disk to perform the sort. Disk I/O is orders of magnitude slower than RAM, meaning you have successfully traded a crash for high latency. To truly fix this—and scale your application—you must optimize your indexing strategy to avoid the in-memory sort entirely. The Root Cause: Blocking Sort MongoDB has a strict internal limit of  100MB  of RAM for blocking sort operations. A  Blocking Sort  occurs when the execution plan cannot obtain the sort order from an index. Consequently, MongoDB mu...

How to Fix "Creation of dynamic property is deprecated" in PHP 8.2+

  If you are upgrading a legacy codebase to PHP 8.2, your logs are likely flooding with this message: Deprecated: Creation of dynamic property ClassName::$propertyName is deprecated This is not a bug in the PHP interpreter. It is a deliberate language change to enforce stricter object definitions. In PHP 9.0, this deprecation notice will become a fatal  ErrorException , crashing your application. Here is the technical breakdown of why this is happening and the three specific strategies to resolve it. The Root Cause: Object Shapes and Optimization Historically, PHP allowed developers to assign values to undeclared properties on any object. While flexible, this behavior incurs significant technical debt: Performance:  PHP engines (Zend) rely on "object shapes" (hidden classes) to optimize property access. When you dynamically add properties, you mutate the object's shape at runtime, forcing the engine to de-optimize and fall back to slower hash-table lookups. Maintainabilit...