I was looking to work with a tool that would help me reflect transactions on my personal database. I was thinking of using demux but a lot of people suggested state history plugin. I want to know the difference between the two and when to choose either of them.
Both state_history_plugin and demux can be used to cache the contract action data into database/memory for fast access in a structured manner.
State_history_plugin is block.one recommended plugin that comes with eosio setup which can be used to cache the full block information (i.e. inline action data) in file.
nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::state_history_plugin --data-dir /Users/mydir/eosio/data --config-dir /Users/mydir/eosio/config --access-control-allow-origin='*' -- contracts-console -http-validate-host=false --state-history-dir /shpdata --trace-history --chain-state-history --verbose-http-errors --filter-on='*' --disable-replay-opts >> nodeos.log 2>&1 &
The nodeos command above adds the state history plugin --plugin eosio::state_history_plugin storing the chain data in a directory called /shpdata under the --data-dir --state-history-dir /shpdata storing both trace history and chain-state-history --trace-history --chain-state-history. To run the state history plugin you are required to --disable-replay-opts.
Once nodeos is running the state history plugin, you need to run fill-postgresql (or an alternative connector) to store the chain data in a postgresql database for querying.
You can store custom block data into postgresql database in custom structured manner.
Edit: State history plugin also provide Http RPC interface.
Demux on the other hand is a open source module that can be integrated with application to fetch and filter information from block and store in any database you want in a traditional manner.
Only advantage of demux over state_history_plugin is that you can integrate any database with demux and can easily filter information in a traditional manner.