How to avoid empty transaction entity from being persisted?


I’ve been working on a way to optionally transact something in datomic cloud and noticed that if my tx-data vector is empty (like {:tx-data []} the response from d/transact still includes a single Datom in the :tx-data.

{:db-before {:database-id "4c842e8a-aee2-4b52-9361-fd5e7183c02c",
             :db-name "2018-11-13",
             :t 733484,
             :next-t 733485,
             :type :datomic.client/db},
 :db-after {:database-id "4c842e8a-aee2-4b52-9361-fd5e7183c02c",
            :db-name "2018-11-13",
            :t 733485,
            :next-t 733486,
            :type :datomic.client/db},
 :tx-data [#datom[13194140266797 50 #inst"2019-04-24T19:42:43.232-00:00" 13194140266797 true]],
 :tempids {}}

I’m assuming that datom is the transaction entity itself. Is there any way to prevent the transaction entity from being created?
Is throwing an exception inside a transaction-function sufficient? If so, are there problems with doing that frequently (Hundreds of times per second) assuming wrap the transaction in a try-catch?


As you surmised, transactions will always include at least one datom (the :txInstant datom).
You can definitely throw from within your transaction function to abort the transaction without writing anything, but I would recommend detecting the potential empty transaction prior to issuing it if possible. Large numbers of aborted frequent transactions will not inherently be a problem, but the transactional stream is serialized, so they will be “in line” with any other transactions the system is attempting to issue.