PocketBase:一个文件搞定后端的极简开发方案
PocketBase: The Minimalist Backend Solution in a Single File
| iDev Engineering | 2026-09-02T01:02:55
PocketBase 将数据库、身份认证、文件存储和实时订阅打包为一个可执行文件,为原型开发和小型项目提供了开箱即用的后端解决方案。
PocketBase bundles database, authentication, file storage, and real-time subscriptions into a single executable, providing an out-of-the-box backend for prototypes and small projects.
PocketBase 是什么PocketBase 是一个用 Go 语言编写的开源后端应用,它的独特之处在于将整个后端基础设施浓缩为一个不到 40MB 的可执行文件。启动后即自动提供 RESTful API、实时数据订阅、用户身份认证、文件上传和管理后台界面。底层数据存储基于 SQLite,无需安装和配置任何外部数据库。功能全景PocketBase 内置的功能远比想象中丰富。数据层面,它提供了类 Firestore 的集合与记录管理,支持字段级别的验证规则和关系定义。认证层面,支持邮箱密码、OAuth2(Google、GitHub 等)和一次性密码三种方式。实时层面,基于 SSE(Server-Sent Events)实现了集合级别的数据变更推送。权限层面,每个集合可独立配置 List、View、Create、Update、Delete 五种操作的访问规则,支持基于记录字段和用户属性的动态表达式。适用场景与限制PocketBase 非常适合以下场景:MVP 和原型快速验证(10 分钟搭建完整后端)、个人项目和小型团队工具、移动应用的轻量后端、以及 JAMStack 网站的内容管理。但它也有明确的边界:SQLite 不支持水平扩展,不适合日活超过 10 万的高并发场景;单文件架构意味着无法自定义中间件和复杂业务逻辑(除非使用 Go 扩展)。部署极简体验PocketBase 的部署简单到令人惊叹:下载二进制文件,运行 ./pocketbase serve 即可。数据存储在同目录下的 pb_data 文件夹中。备份只需复制该文件夹,迁移只需移动整个目录。我们在一台 2 核 4GB 的云服务器上运行了一个 PocketBase 实例,稳定服务了 5000 名注册用户和日均 3 万次 API 调用。
What Is PocketBasePocketBase is an open-source backend application written in Go whose unique value lies in condensing entire backend infrastructure into a single executable under 40MB. On startup, it automatically provides RESTful APIs, real-time data subscriptions, user authentication, file uploads, and an admin dashboard. It uses SQLite for data storage, requiring no external database installation or configuration.Feature OverviewPocketBase's built-in features are remarkably comprehensive. For data, it provides Firestore-like collection and record management with field-level validation rules and relationship definitions. For auth, it supports email/password, OAuth2 (Google, GitHub, etc.), and one-time passwords. For real-time, it implements collection-level data change push via SSE (Server-Sent Events). For permissions, each collection can independently configure access rules for List, View, Create, Update, and Delete operations, supporting dynamic expressions based on record fields and user attributes.Use Cases and LimitationsPocketBase is ideal for MVP and prototype rapid validation (complete backend in 10 minutes), personal projects and small team tools, lightweight mobile app backends, and JAMStack site content management. However, it has clear boundaries: SQLite does not support horizontal scaling, making it unsuitable for high-concurrency scenarios exceeding 100K DAU; the single-file architecture means no custom middleware or complex business logic without Go extensions.Minimalist DeploymentPocketBase deployment is astonishingly simple: download the binary, run ./pocketbase serve. Data resides in a pb_data folder in the same directory. Backup means copying that folder; migration means moving the entire directory. We ran a PocketBase instance on a 2-core 4GB cloud server, stably serving 5,000 registered users with 30,000 daily API calls.