The more I work with flat files, the more I love them over a traditional database setup. Let's dig in! What is flat file storage?A flat is just a file you can read and write with a text editor program. It could be A year or so ago, I migrated all of my membership sites over to flat files. Every user has a JSON file with their password (hashed, of course!) and an array of their purchases. Every session token is a JSON file with the associated username stored in it. All of the files are stored in a nonpublic part of the server that cannot be accessed with HTTP. On the backend, I can use PHP to read the file contents, parse it JSON, and extract values. It works more-or-less like how a SQL database would, but less complicated. Why flat file storage rocksIt makes local development, debugging, and fixing things really easy. I can download files and open them in Sublime text to figure out what's wrong. I can move files from my computer to the server and back. I never have to write a SQL query. Hell, I can just browse with FTP if I want! (Just to reiterate, I cannot read or view user passwords. They're hashed using PHP's built-in password hash and validation algorithm, which is currently BCrypt.) Data portabilityAll of this is about to payoff big for me, because I need to migrate servers. For nearly a decade, I've used ServerPilot to manage a dozen or so websites on a single DigitalOcean droplet. That used to be hard to do, and ServerPilot made it easy. Now, DigitalOcean has tons of tutorials on how to do the same thing yourself. A year ago, ServerPilot informed me they wouldn't be updating my server anymore, because the Linux version is too old. They recommend migrating to a new droplet rather than updating (I tried and stuff kept breaking). But migrating would mean I'd lose the grandfathered free plan I was on. Then, a few months ago, they mentioned the "free forever" plan I was on (that is no longer available), is not actually free forever. They're getting rid of it, and I won't be able to manage my sites through ServerPilot anymore until I switch to a paid plan. I'm not mad. I've gotten a very valuable service for free for years, and this stuff costs money to run. But the price jump is not insignificant. If I still had databases to migrate, I'd be freaking out. But I don't! Now, migrating is as simple as downloading some files with an SFTP client, then uploading them to a new server. What about performance?One of the criticisms of flat file storage is performance. I imagine if I had a single JSON file with all of my customers, and lots of looking up to do, a SQL server probably would be more performant. But I don't have that. I have lots of small files, one for each customer. I get the file, read a value from it or write a new value into it, and then I'm done. It's all very fast. Cheers, Want to share this with others or read it later? View it in a browser. |
0 Komentar untuk "[Go Make Things] Flat files and data portability"