freeeの会計データ整合性 — 仕訳バランスの自動検証

freeeは個人事業主から中堅企業まで幅広く利用されているクラウド会計サービスです。会計データは一円たりとも狂ってはならず、税務調査や監査に耐える正確性が求められます。本記事では、freeeが仕訳データの整合性をどのように担保しているかを整理します。
freee is a cloud accounting service used widely from sole proprietors to mid-sized companies. Accounting data must not be off by even one yen, and accuracy that withstands tax audits and external audits is required. This article organizes how freee guarantees the integrity of journal entry data.
複式簿記の強制
複式簿記の基本原則は、すべての取引が借方と貸方に同じ金額で記録されることです。freeeでは、仕訳を書き込むトランザクション内でデータベース制約とアプリケーション層の両方で借方合計と貸方合計が一致することを検証します。
The basic principle of double-entry bookkeeping is that every transaction is recorded with the same amount on both the debit and credit sides. At freee, when writing a journal entry, both database constraints and the application layer verify within the same transaction that debit totals match credit totals.
冪等性キーによる二重計上の防止
銀行APIや決済サービスからの連携データを取り込む際、ネットワーク障害や再試行によって同じ取引が二重に登録される危険があります。freeeでは外部システムの取引IDを冪等性キーとしてユニーク制約を掛けることで、何度リクエストが届いても結果が一つに収束するように設計されています。
When importing data from bank APIs or payment services, there is a risk that the same transaction could be registered twice due to network failures or retries. freee applies a unique constraint on the external system's transaction ID as an idempotency key, designed so that no matter how many times a request arrives, the result converges to a single posting.
監査証跡の設計
会計データは編集や削除されても、その履歴が完全に残る必要があります。freeeは追記専用のイベントログを採用し、すべての変更を不変な形で保持します。誰が、いつ、どのフィールドを、どの値から、どの値に変えたかが後から完全に再現できることが監査対応の前提です。
Even when accounting data is edited or deleted, its history must remain completely. freee adopts append-only event logs and retains all changes in immutable form. The ability to fully reproduce later who changed which field, when, and from what value to what value is the precondition of audit compliance.
締め後の遡及修正
月次や年次の締めが終わった後に誤りが見つかることもあります。既に確定した期を直接書き換えることは禁止され、代わりに「修正仕訳」を当期に追加するのが正しい処理です。freeeでは締めロック機能によって過去の期間への書き込みを排他し、修正は必ず新しい仕訳として記録されます。
Errors are sometimes found after monthly or annual closings have ended. Directly rewriting an already-finalized period is forbidden; instead, the correct handling is to add a "correction journal entry" in the current period. freee's closing-lock feature excludes writes to past periods, and corrections are always recorded as new journal entries.
バッチ照合による二重チェック
書き込み時の検証に加え、freeeは夜間バッチで全テナントの勘定残高を再計算し、既存の残高テーブルと突き合わせます。差分が発生した場合は即座にアラートを飛ばし、原因を追跡します。これは「書き込み経路にバグがあっても気付ける」ための最後の砦です。
In addition to write-time verification, freee runs a nightly batch that recalculates account balances for all tenants and compares them against the existing balance table. When a difference occurs, an alert fires immediately and the cause is traced. This is the last line of defense to "notice even when there is a bug in the write path."
リコンサイル失敗時の運用
照合で差分が出た場合、安易に残高テーブルを書き換えることは絶対に避けます。必ず原因となった仕訳を特定し、正規の修正フローで修復します。人による手作業を挟むほど、データの一貫性が損なわれるリスクが高まるからです。
When a reconciliation difference appears, thoughtlessly rewriting the balance table is absolutely avoided. The journal entry causing the discrepancy is always identified and repaired through the normal correction flow. The more manual intervention is inserted, the higher the risk that data consistency is impaired.
テナントごとの排他制御
同じ勘定に対する同時書き込みを安全に捌くため、freeeはテナントIDと勘定IDをキーとする行ロックを使います。残高更新は必ずこのロックを取った後に行われ、読み取りと書き込みの間に割り込みが入っても結果が壊れないように設計されています。
To safely handle simultaneous writes to the same account, freee uses row locks keyed by tenant ID and account ID. Balance updates are always performed after acquiring this lock, designed so that even if interruptions occur between read and write, the result is not broken.
おわりに
freeeの整合性戦略は一つの銀の弾丸ではなく、「書き込み時検証」「冪等性キー」「追記専用監査ログ」「締めロック」「夜間再計算」という多層の防御の組み合わせです。金融データを扱うシステムでは、一つの層が失敗しても他の層が捕捉できる多重防御が必須です。
freee's integrity strategy is not a single silver bullet, but a combination of layered defenses: write-time verification, idempotency keys, append-only audit logs, closing locks, and nightly recalculation. In systems handling financial data, multi-layered defense — where other layers can catch failures even if one layer fails — is essential.