How to quickly get the balance of any bitcoin address? (with no third-party API) As some people have mentioned (eg. here), the only way to get the balance of an address in bitcoin core was to import it as a watch-only address and rescan the blockchain. Starting with bitcoin core v0.17, we can use the scantxoutset command, however this is quite slow:

&gt; time bitcoin-cli scantxoutset "start" "[\"addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)\"]"
{
  "success": true,
  "searched_items": 64162818,
  "unspents": [
    {
      "txid": "9796cee98fa88efcb9fdb954188d276b73d6e76719af6b5470ad23a2f744ecca",
      "vout": 1,
      "scriptPubKey": "76a91446255848182640edff4d178f365d7824513bc28d88ac",
      "desc": "addr(17Pu3CEx34YX8bpGATq45PfL2fGBCPcr2u)#x2q6xgrk",
      "amount": 0.02155141,
      "height": 607852
    }
  ],
  "total_amount": 0.02155141
}

real    0m42.419s
user    0m0.007s
sys 0m0.003s 


42 seconds is quite slow, I would like to get something comparable to block explorers (less than 2 seconds). Is it possible to achieve faster results with some advanced bitcoin core configuration?

Or, is there any open-source project I could use to index the UTXO set by address? Not sure if libbitcoin, bitcoinj, bitcoinJS, etc. are able to do this faster. Some tool block explorers might use to provide this service would be what I am looking for.
There is no way to enable faster querying for arbitrary addresses than scantxoutset in bitcoind.

Explorers provide this functionality by maintaining a separate database of all addresses and transactions which is optimized for that kind of query. Bitcoin Core, on the other hand, is optimized for consensus related queries, which are largely a hashset lookup for a given input for a transaction.

You could try running something such as ElectrumX, which backs the electrum wallet, or Bitcore, which backs many of Bitpay's wallet and explorer services.