小型App数据存储选型:FTP文件(JSON/XML)还是数据库?
Hey there! Let’s walk through your scenario step by step—you’ve built a simple app with an FTP server that can store data in JSON/XML files or a database, supports multi-client read/write operations, and has a max limit of 100 data entries. Your concern about concurrent file access is totally valid, so let’s break this down:
首先,JSON/XML 文件的并发读写确实会有问题
You’re right to worry here. When multiple clients try to read and write the same JSON/XML file at the same time, race conditions are almost inevitable. For example:
- Client A reads the file, starts modifying an entry
- At the same time, Client B reads the same original file and modifies a different entry
- Both clients write their changes back—one of the modifications will get overwritten, leading to data loss or inconsistency.
File system locks (like exclusive locks) can help, but they force clients to wait for access, which slows down response times. Even with only 100 entries, frequent concurrent operations will make this problem noticeable. You’d also have to build custom logic to handle lock timeouts, retries, and conflict resolution—extra work that’s totally avoidable.
数据库在小数据量场景下依然是更好的选择
While databases shine with large datasets thanks to indexing, their real value for your use case is built-in concurrency control and transaction support. Even with just 100 entries, a lightweight database (like SQLite, which is file-based and requires no separate server) will handle row-level locking or transactions automatically. This means multiple clients can read/write safely without overwriting each other’s changes.
Plus, you don’t have to reinvent the wheel—database APIs come with mature tools for safe read/write operations, so you can skip writing complex file-handling logic. Deployment is also straightforward: SQLite databases are just single files, so integrating them with your FTP server is no harder than working with JSON/XML.
针对你的场景的具体建议
Go with a lightweight database like SQLite. It’s perfect for your 100-entry limit, eliminates the concurrent file access risk entirely, and requires minimal setup. You’ll save yourself hours of debugging file conflicts, and your app will be more reliable for multi-client use.
内容的提问来源于stack exchange,提问作者Nenad Birešev

