TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Is SQLite suitable for command sourcing application?

7 pointsby aabbcc1241about 4 years ago
I used to work with LevelDB (with typescript). It&#x27;s very easy and fast to develop with.<p>Recently I&#x27;m playing with sqlite, aim to save some disk space by normalizing the data.<p>I spend quite some time to define the tables and write insert queries in normalized format. I even try to &quot;compact the data&quot; by using a table to store all unique string then reference to it&#x27;s primary key.<p>I suppose storing the data in the rigid and compact format should result in smaller file size but it seems I am wrong.<p>The data I&#x27;m storing are immutable request log (timestamp, type, and input) for command-sourcing style of server. The current state of server are not persisted. Each time the server is restarted, it just replay all the request logs to restore the state.<p>The architecture is inspired from cqrs and event sourcing, except the write model is simply the storage, the read model is in a single process&#x27;s memory, and it&#x27;s sourcing from the commands, not events. (Though some kind of attempt-commands spawn verified-commands and are skipped when replay to avoid applying side-effect twice)<p>File size for reference: JSON Files 409M, SQLite 114M, LevelDB 63M.<p>The SQLite file is smaller than LevelDB after zip, but access sqlite over zip file doesn&#x27;t sound a good solution.

4 comments

nknealkabout 4 years ago
I believe LevelDB automatically passes blocks through snappy compression, hence the smaller size. SQLite has an extension[1] that will do something similar. I’ve never used it so I can’t comment on how it might work for your use case.<p>[1] <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;zipvfs&#x2F;doc&#x2F;trunk&#x2F;www&#x2F;readme.wiki" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;zipvfs&#x2F;doc&#x2F;trunk&#x2F;www&#x2F;readme.wiki</a>
HelloNurseabout 4 years ago
Why did you switch from LevelDB to SQLite, apparently without new features? Less than double the file size could be an acceptable price to pay for a performance improvement, or even to try out different technology.<p>Did you analyze where SQLite wastes space compared to LevelDB? If standard compression removes all redundancy, I&#x27;d guess there&#x27;s simply some slack in pages and individual fields, or unnecessary indices.
评论 #26938307 未加载
bjourneabout 4 years ago
Does size matter? Otherwise why bother? For example, you could probably save a bit of space by storing the timestamps as unix time stamps (if you are using strings), but it may not be a useful use of your time. Also, for larger databases (gigabytes) SQLite may catch up to LevelDB.
评论 #26938321 未加载
manxabout 4 years ago
Did you try to run VACUUM?<p><a href="https:&#x2F;&#x2F;www.sqlitetutorial.net&#x2F;sqlite-vacuum&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.sqlitetutorial.net&#x2F;sqlite-vacuum&#x2F;</a>
评论 #26944152 未加载