The decentralized design of blockchain has limited performance.
Transactions can take several minutes or even one hour to be committed to the blockchain.
Due to the long commit time and high transaction fees of the public blockchain where the fees are largely
dependent upon the transaction amount, it is often infeasible to store every micropayment transaction
on the blockchain network.
During a recent peak in demand, the average fee per transaction for Bitcoin blockchain has risen up
to 55 USD on chain transactions are suitable for transactions with medium to large monetary value relative
to the transaction fees.
Micropayments transactions are too expensive to be performed on top of blockchain because the required
transaction fees might be higher than the monetary value associated with the transaction itself.
Thus, micropayments should be exchanged off chain while periodically recording settlements for a larger
amount on chain.
Such a payment channel can be generalized for arbitrary state updates for more general purposes other
than monetary value.
State channel pattern provides the solution where the micropayments can be carried out off chain and
the finality of the transactions can be recorded on chain.
There are few forces which led to the creation of state channel pattern.
The first one is latency.
Blockchain transactions may take a long time to be committed, while users expect micropayments to happen
instantaneously.
For example, if you are buying a coffee using Bitcoin, then you might have to wait for a day for your
transaction to process.
The second force is scalability.
Blockchain has limited scalability because every bit of data is replicated across all nodes and kept
permanently.
This also causes a problem because once a transaction has submitted, it has to be delivered to every
node inside the network.
And finally, the consensus has to be achieved to make the transaction permanent on top of the blockchain.
The third force is the cost of storing data on public blockchain cost real money.
The transaction fees of individual micropayment transaction might be higher than the monetary value
associated with the micropayment transaction.
It could be possible that you are paying for a coffee, but the fees associated for payment for that
coffee might be higher than the coffee itself.
State channel pattern Establish a payment channel between two participants with the deposit from one
or both sides of the participants, which is logged up as a security in a smart contract for the lifetime
of the payment channel.
The payment channel keeps the intermediate states of the micro payment option and only stores the finalized
payment on chain.
The frequency of transaction settlement depends on the use case and the agreement between the two sides.
For example, in scenarios around utilities, internet service providers or electricity companies can
be established with payment channels with their consumer for an agreed billing period, for example,
a month or a week.
As the consumer uses data or energy daily, the intermediate state is stored in the channel until the
end of the month, when the channel is closed to finalize the payment of that month on top of the blockchain.
A network of micro payment channels can be built where the transactions take place entirely off the
blockchain and exclusively between the participants across multiple hops where they are needed.
Only the final transaction that settles the payment for a given channel or a set of channels is submitted
to the blockchain.
The technology is used to implement state channel are specific to blockchain platform.
For example, Lightning network on the Bitcoin Blockchain is a proposed implementation of hash timelock
contracts which are bidirectional payment channels and allow secure payments across multiple peer to
peer channels.
A hash timelock contract is a type of payment that use the features of script like hash locks and time
locks to require that the receiver of the payment acknowledges receiving the payment prior to a deadline
by generating a cryptographic proof.
Several blockchain platforms also utilizes state channel pattern.
If you take the example of blockchain platform, it utilizes the state channel platform to maintain
the micro payments.
And finally, the finality of the transaction is stored on top of the blockchain.
This can be enabled with the help of flows with the Corda blockchain.
The benefits of state channel patron is that it provides speed without involving blockchain for every
transfer.
The off chain transactions can be settled without waiting for the blockchain network to process the
transaction.
It also provides throughput The number of off chain transactions that can be processed is not limited
by the configuration of the blockchain, such as block size, block interval, gas limit, etcetera
and thus a much higher throughput can be achieved than from a on chain transaction.
It also provides you privacy because other than the final settlement transaction, the individual off
chain transactions do not show up in the public ledger.
Thus, the details of these intermediate off chain transactions are not publicly visible.
Finally, it also provides you cost benefits if a public blockchain is used.
Only the final settlement transaction costs transaction fees to be included in the blockchain.
Direct individual off chain transactions do not cost any money.
Multihop transactions may cause small transaction fees, which are typically charged as a percentage
of the transacted amount.
There are also drawbacks related to state channel pattern.
One of the major drawback is related to trustworthiness.
The individual off chain micropayment transactions might not be as trustworthy as the on chain transactions
because the micropayment transactions are not stored in a immutable data store.
The intermediate state of the payment channels might be lost or the payment channels might get closed.
Another drawback related to the same is about reduced liquidity.
To establish a payment channel, money from one or both sides of the channel needs to be locked up in
a smart contract for the lifetime of the payment channel.
The liquidity of the channel participants is thereby reduced.
Another drawback related to state channel pattern is about wallets.
A new wallet or extension to the existing wallet is needed to support the micro payment, which is used
with the blockchain platforms.
Some of the known implementations of state channel platform are about Lightning Network, which uses
an off chain protocol to enable micro payments on Bitcoin and several other cryptocurrencies.
Micro payments are enabled by establishing a bi directional payment channel through committing a funding
transaction to the blockchain.
This can be followed by a number of micro payments transactions that update the distribution of the
funds within the channel without broadcasting transactions to the blockchain network.
The payment channel can be closed by broadcasting the final version of the funding transaction to settle
the payment.
Another implementation of state channel pattern is with the Raiden Network on Ethereum Blockchain,
which is a similar solution as Lightning Network.
The basic idea is to avoid the consensus bottleneck by leveraging a network of off chain payment channels
that allow to securely transfer monetary value.
Smart contracts are used to deposit value into the payment channels.
In this image, you can see the state channel pattern in action.
On the left hand side, we have Onchange, which is the blockchain itself.
And on the right hand side we have off chain where we have created a channel where micropayments are
being transacted.
Several group of users can deposit a small amount in terms into the micro state channels and these amounts
will be transacted between each other.
Once the channel is closed, the finality of the transaction will be settled on top of the blockchain.
This method provides much more performance than the traditional blockchain transactions.
Also, it reduces the cost associated with the traditional blockchain transactions.
For example, a telecommunication service can create a micro payment channel for maintaining the data
used by the users.
They can charge the users as per per kilobyte of the data, and that can be recorded as micro payments
with the user on top of the micro payment ledger, which they are hosting once the time period for the
channel has been expired, let's say it's one month, then the total transaction amount could be calculated
and then processed on top of the blockchain which is immutably visible to the user, thus creating a
much more accessible infrastructure for both the users and the service providers.
So that was about the data management patterns and you have seen that how different patterns provide
the solution for some of the common problems related to data management with the blockchain services
and how you can use these patterns to create your own architecture decisions.
In the next lecture we are going to discuss about the security patterns and we are going to go through
each security pattern in detail and how you can use those security patterns with your enterprise solutions.
If you have any queries, feel free to contact us at info at the rate v2 blocks.com.