As storing persistent data on blockchain is costly due to the storage operation being gas-expensive, what are the solutions to store mutable data outside the realm of blockchain from within a smart contract? I heard about IPFS and Swarm, but didn't really understand how they interface as a storage layer with a smart contract. Let's say we are to design an imaginary banking application (DApp) that should handle a million customers. We need to read/write the customer information including the account balance in a persistent storage. The business logic is implemented in a smart contract. But, how do we deal with this huge volume of data in a storage later?
In this case you will use the Blockchain ( using a smart contract) as a source of truth that for each document will provide an unique identifier (the document's hash). Assume for example, that your app registers deals between parties and the deal involves a contract document, you can use an smart contract to save the deal details including the hash of the contract document. In the event that is necessary to verify the authenticity of the document, taking the hash of it and comparing it with the hash stored in the smart contract will be sufficient proof that the document has or hasn't been modified. If the document is modified "legally" your app will register the hash of the modified doc. Like this you can store your data anywere, the advantage of IPFS is that the storage is decentralized but the idea is the same when you think about the smart contract.
If your app produces many transaction per hour, probably is necessary to look for a more efficient solution, or maybe to change the logic in such way that you only save the hash of an snapshot of your database (root of the Merkel tree of your data) at particular times, instead of saving individually the hashes of each document.
Hope that this helps