Urgent.News

What's breaking now, across thousands of outlets.

Tech

No database on purpose: flat files are enough for a downloader

When I rebuilt my video downloader in plain PHP for shared hosting, the first thing I decided was what not to build. There would be no database. No MySQL, no SQLite, no tables, no migrations, no admin panel. Just files in folders. That sounds reckless if you have spent your career around databases. It felt reckless to me too, at first. But a year in, I have not missed one, and the decision is the…

The story of a video downloader built using plain PHP for shared hosting brings to light the decision to forego databases in favor of flat files. This choice was not made recklessly, but rather as a deliberate move to keep the system simple and maintainable for a single individual.

The essential functions of the downloader are streamlined into three core components: a per-IP rate-limit counter, a cache of recent provider responses, and an error log. Each of these is stored as a separate file, eliminating the need for a complex database system. The rate limiter is managed by a JSON file per IP address, while the cache is organized as a folder of JSON files named with a hash of the video URL, each with a built-in expiry time. The error log is a straightforward text file, recording failures without any sensitive user data.

The reason for this file-based approach is rooted in the constraints of shared hosting. Shared hosting limits the use of databases, requiring additional services, credentials, and potential points of failure. By opting for flat files, the downloader avoids these complications. Moreover, files do not have connection limits, unlike MySQL, which can become a scarce resource on cheap plans, potentially blocking new visitors if connections are already in use.

Performance-wise, accessing and modifying small JSON files is swift and efficient, requiring no database query planner or index maintenance. This simplicity not only makes debugging easier, involving basic commands like ls and cat, but also keeps the site's state easily back up-able by simply zipping the folder.

However, it is acknowledged that flat files have their limitations. They do not handle concurrent writes gracefully, potentially leading to file corruption issues if multiple requests attempt to write to the same file at once. This can be mitigated using flock(), but this may not suffice under heavier load. Additionally, flat files do not scale across multiple servers, as files on different servers will diverge, and searching through them is rudimentary, lacking SQL-like query capabilities.

Despite these limitations, the current setup is suitable for the site's scale: a single server, one person, and a modest traffic volume. The decision to implement a database only when necessary, such as when dealing with relationships between records, large-scale queries, or state shared across servers, ensures that resources are not spent on unnecessary complexity.

The takeaway from this story is that the simplest solution often proves to be the most effective. As long as the site's requirements remain within the capabilities of flat files, maintaining this approach avoids unnecessary complications and aligns with the principle that the most straightforward solution is often the best. The site, ramrom.io, exemplifies this philosophy, running on PHP, flat files, and nothing else, demonstrating that simplicity can indeed be the best strategy.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Escrow for agent-to-agent work: what it covers and what it doesn't

When one AI agent pays another for work, two failure modes matter: the worker never delivers, or it delivers something that fails the agreed checks.

  • Escrow systems provide payment automation and refund mechanisms for agent-to-agent transactions.
  • Fixed-price orders must detail scope, inputs, outputs, acceptance criteria, price, and deadline.

You found the why. The reason to finish is smaller than you think.

csm18 wrote this under my last post, and it stayed with me all morning: "It became a normal thing for me to start a lot of projects and end with only 2 or 3. But your post made me think why?

  • Focusing on a single person with a deadline provides a concrete reason to finish projects.
  • The writer's unfinished project serves as an example of the importance of a clear destination.
  • Naming the person who would notice the project can motivate completion.

More from Thursday 12 November →