Categories
Software Technology

How to personalize search results with Elasticsearch

Only a few years ago, a simple search engine was enough — that is a search criteria based on a relational database was enough. Yet, there are no universal and irreplaceable solutions. Thanks to data growth, new search tools have appeared. An undeniable advantage is their ability to influence search results and sorting. I’d like to provide a few examples of how to personalize search results with Elasticsearch.

Searching for data is and will be an indispensable part of almost every web application. In the past few years, the approach to data searches has changed. With the development of web applications and the moving of large sets of data to online services, the amount of data has increased rapidly. Existing search tools and solutions have become insufficient. A good, old search engine based on MySQL is no longer fast and flexible enough.

How to personalize search results in Elasticsearch

Table of contents:

  1. What can those new search tools do?
  2. Code introduction
  3. Example 1: Personalize search weights
  4. Example 2: Personalize results with score functions
  5. Example 3: Score script
  6. Conclusion
 

What can those new search tools do?

A search engine used for searching through job applications would be a great example here. Let’s say that we have a web application with multiple companies. Each company stores user job applications. Almost everyone knows how hard it is to get a good employee that fits our requirements.
Our search engine needs to have multiple search criteria. This sounds quite easy, but what if every company wants to search for applicants in its own, personalized manner? There are many ways to do this. One of them is to add “weights” to certain search parameters. Going further, we can attach these weights to a certain company and give their company admins permissions to manage them.
Elasticsearch is one of the search tools that help you create a search engine with personalized weights. We can now create an advanced search engine in an easy way. What’s more, we’ll have the possibility to affect the results. Thanks to Elasticsearch, we not only get an advanced search engine. We ensure the scalability and easier development of our application in case new functionalities are added in the future.
The examples here are based on the current version — Elasticsearch 6.8.11 and is an update to a previous guide.
I’d like to base on two types of variables attached to user applications:
Let’s say we’ve got two statuses of employment types:
1 – Permanent job
2 – Temporary job
and two statuses of work types:
1 – Full time
2 – Part time
I filled Elasticsearch with some sample data:
RECORD ONE (candidate1):
Employment type = 1
– Work type = 1
RECORD TWO (candidate2):
Employment type = 2
– Work type = 1
RECORD THREE (candidate3):
Employment type = 1
– Work type = 2 

 

Code introduction

A basic search query and its result without weights looks just like this:
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

GET gs_application/application/_search
{
  "_source": [
    "fullname"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "profile.work_types",
            "query": {
              "bool": {
                "must": [
                  {
                    "terms": {
                      "profile.work_types.id": [
                        1
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "profile.employment_types",
            "query": {
              "bool": {
                "must": [
                  {
                    "terms": {
                      "profile.employment_types.id": [
                        1
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

[/dm_code_snippet]
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 2.0,
    "hits" : [
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "78",
        "_score" : 2.0,
        "_source" : {
          "fullname" : "surname1 candidate1"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "79",
        "_score" : 1.0,
        "_source" : {
          "fullname" : "surname2 candidate2"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "80",
        "_score" : 1.0,
        "_source" : {
          "fullname" : "surname3 candidate3"
        }
      }
    ]
  }
}

[/dm_code_snippet]
Let’s remember the weights:
1 → 2 (candidate1 weight)
2 → 1 (candidate2 weight)
3 → 1 (candidate3 weight)

 

Example 1: Personalize search weights

Project weights configuration:
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

similarity_tresholds:
    work_types.id:                     1.0
    employment_types.id:               2.0
    example.id:                        10.0

[/dm_code_snippet]
I would like to show an example based on Symfony 3.4 and FosElasticaBundle 5.1.1, but feel free to try with different stack (almost each major programming language has a great Elasticsearch library which supports mapping, queries and more).  
In this case, weights are defined globally in one of the parameter files in Symfony. But nothing stands in the way of moving this configuration to a database and attaching them to certain companies.
And how does it look in PHP?
We passed declared weights in the constructor. Then, in the class responsible for the manipulation of weights, we have a method for checking if we have defined weights that we can attach to certain search criteria.
At the end, we create a part of a search query with suitable weight to Elasticsearch query.
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

private array $filtersToBoost;
public function __construct(array $filtersToBoost)
{
    $this->filtersToBoost = $filtersToBoost;
}
private function applyBoostIfExists(string $filterName, BoolQuery $boolQuery):  BoolQuery
{
    if (array_key_exists($filterName, $this->filtersToBoost)) {
        $boolQuery->setBoost($this->filtersToBoost[$filterName]);
    }
    return $boolQuery;
}

[/dm_code_snippet]

In the results, we get a simple Elasticsearch query where:
– work type parameter has a weight = 1
– employment type parameter has a weight = 2.
It means that the employment type parameter is 2 times more important than the work type parameter. 
In practice, it looks just like this:
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

GET gs_application/application/_search
{
  "_source": [
    "fullname"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "profile.work_types",
            "query": {
              "bool": {
                "boost": 1,
               "must": [
                 {"terms": {
                   "profile.work_types.id": [
                     1
                   ]
                 }}
               ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "profile.employment_types",
            "query": {
              "bool": {
                "boost": 2,
                "must": [
                  {
                    "terms": {
                      "profile.employment_types.id": [
                        1
                      ]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

[/dm_code_snippet]
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 3.0,
    "hits" : [
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "78",
        "_score" : 3.0,
        "_source" : {
          "fullname" : "surname1 candidate1"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "80",
        "_score" : 2.0,
        "_source" : {
          "fullname" : "surname3 candidate3"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "79",
        "_score" : 1.0,
        "_source" : {
          "fullname" : "surname2 candidate2"
        }
      }
    ]
  }
}

[/dm_code_snippet]
In result we get:
1 → score:3 (candidate1) user with employment type = 1 – score boosted
2 → score:2 (candidate3) user with employment type = 1 – score boosted
3 → score:1 (candidate2)
As we can see, candidates with employment type = 1 are scored higher. This example shows how can we manage search weights in a simple way.

 

Example 2: Personalize results with score functions

Search results in Elasticsearch are sorted by “score” value. If the personalization of weights isn’t good enough or doesn’t fit our needs, we have the option to multiply the score value of a record by the weight parameter and boost_mode.
Let’s say we’d like to see the records with employment type = 1 have their scores increased 4-times.
The Elasticsearch query would look like this:
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

GET gs_application/application/_search
{
  "_source": [
    "fullname"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "profile.work_types",
            "query": {
              "bool": {
                "boost": 2,
                "must": [
                  {
                    "terms": {
                      "profile.work_types.id": [
                        1
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "profile.employment_types",
            "query": {
              "function_score": {
                "query": {
                  "terms": {
                    "profile.employment_types.id": [
                      1
                    ]
                  }
                },
                "functions": [
                  {
                    "filter": {
                      "terms": {
                        "profile.employment_types.id": [
                          1
                        ]
                      }
                    },
                    "weight": 4
                  }
                ],
                "boost_mode": "multiply"
              }
            }
          }
        }
      ]
    }
  }
}

[/dm_code_snippet]
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 6.0,
    "hits" : [
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "78",
        "_score" : 6.0,
        "_source" : {
          "fullname" : "surname1 candidate1"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "80",
        "_score" : 4.0,
        "_source" : {
          "fullname" : "surname3 candidate3"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "79",
        "_score" : 2.0,
        "_source" : {
          "fullname" : "surname2 candidate2"
        }
      }
    ]
  }
}

[/dm_code_snippet]
We get:
1 → score: 6 (candidate1) – employment type = 1 – score boosted even more
2 → score: 4 (candidate3) – employment type = 1 – score boosted even more
3 → score: 2 (candidate2)

 

Example 3: Score script

An extension of the below functionality is an inline script – called painless scripting language. With that solution, we can personalize results based on the record we’ve stored in Elasticsearch.
If we want to have candidates who are looking for permanent job (employment type = 1) on the top of the list, then we can use the score script to boost those records 4 times. This is a different way to obtain similar results like we got in previous example, but here we have much more flexibility in manipulating score results for specific documents (records).
An example of an Elasticsearch query:
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

GET gs_application/application/_search
{
  "_source": [
    "fullname"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "profile.work_types",
            "query": {
              "bool": {
                "boost": 2,
                "must": [
                  {
                    "terms": {
                      "profile.work_types.id": [
                        1
                      ]
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "profile.employment_types",
            "query": {
              "function_score": {
                "query": {
                  "terms": {
                    "profile.employment_types.id": [
                      1
                    ]
                  }
                },
                "functions": [
                  {
                    "script_score": {
                      "script": {
                        "params": {
                          "multiplier":  4
                        },
                        "source": "def et = doc['profile.employment_types.id'].value; if (et == 1) {return _score * params.multiplier} else {return _score}"
                      }
                    }
                  }
                ],
                "boost_mode": "multiply"
              }
            }
          }
        }
      ]
    }
  }
}

[/dm_code_snippet]
[dm_code_snippet background=”yes” background-mobile=”yes” bg-color=”#eeeeee” theme=”dark” language=”php” wrapped=”no” copy-text=”Copy Code” copy-confirmed=”Copied”]

{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 6.0,
    "hits" : [
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "78",
        "_score" : 6.0,
        "_source" : {
          "fullname" : "surname1 candidate1"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "80",
        "_score" : 4.0,
        "_source" : {
          "fullname" : "surname3 candidate3"
        }
      },
      {
        "_index" : "gs_application",
        "_type" : "application",
        "_id" : "79",
        "_score" : 2.0,
        "_source" : {
          "fullname" : "surname2 candidate2"
        }
      }
    ]
  }
}

[/dm_code_snippet]
In results we get:
1 → score: 6 (candidate1) – employment type = 1 – score boosted
2 → score: 4 (candidate3) – employment type = 1 – score boosted
3 → score: 2 (candidate2)

 

Conclusion

To personalize search with Elasticsearch is pretty simple. I’d like to show how developers can create advanced search engines easily, based on customer needs. Those above examples are a great starting point for more complicated conditions. 

Categories
Blockchain Finance Financial Services

Stablecoins, rather than cryptocurrencies, might be the future of money

Over the last five years, blockchain has demonstrated the potential to disrupt almost every sector. The global fintech industry aims to build a revolutionary decentralized transparent payment system that uses digital currencies as a means of exchange.

The financial sector will benefit most from this emerging tech, but the prices of the first generation of digital assets, like Bitcoin and Ethereum, are highly volatile, speculative assets. For cryptocurrencies to replace fiat currencies as the future of money, they must have stable prices. This is what led to the creation of stablecoins. In this article, we will discuss what stablecoins are, the various types of stablecoins, and their importance. We shall also look at the recent interest of governments in issuing their digital currencies backed by their native currencies.

Stablecoins, rather than cryptocurrencies, might be the future of money

Table of contents:

  1. Finding the right application for blockchain
  2. Types of stablecoins
  3. Why are stablecoins important?
  4. The case for central bank digital currencies (CBDCs)
  5. Conclusion

Finding the right application for blockchain

As the name suggests, stablecoins differ from mainstream but highly volatile cryptocurrencies, like Bitcoin, Ripple, and Ethereum, in their focus on price stability. In achieving stability from the beginning, stablecoins aim to prevent a scenario like that experienced by Laszlo Hanyecz in 2010.

Hanyecz is an American software programmer who bought two pizzas using 10,000 bitcoins (at a time when one bitcoin was a fraction of a cent). Currently, this transaction would be worth $100 million. Hanyecz wanted to prove a point — this was the first time someone accepted bitcoin as a medium of exchange, but the now-famous story has also become a symbol of the drawbacks of using volatile currency for regular purchases.

Stablecoins allow buyers and sellers to lock in prices. They have their prices pegged to real-world assets, like the U.S. dollars, precious metals, commodities, or property to name a few. Because of their stability, stablecoins are the ideal tools that can link blockchain networks with traditional economies. They help users streamline payments through automation while maintaining liquidity, security, and transparency.

The issue of connecting the blockchain ecosystem with the traditional banking system has persisted for a long time now, but, with the introduction of stablecoins, businesses and the masses will soon be relying on these digital assets to make cross-border payments. Stablecoins bring the benefits of cryptocurrencies with an added advantage of price stability, which is attractive for users looking for cost-effective, instant, and safer means of transactions in day-to-day spending.

Types of stablecoins

Fiat-collateralized

These stablecoins are backed by a fiat currency, like the US dollars. The issuing firm holds real-world assets in a financial institution or partners with a third-party financial provider to keep money on their behalf. The tokens act as a claim of the underlying assets. The same applies to a scenario where commodities, such as precious metals, and bonds back the coins.

Fiat-collateralized stablecoins were the first stablecoins and the easiest to understand for crypto newbies since they are the most common onboarding tools into the crypto space. They are simple, elegant, and more easily trusted by retail users compared to other digital currencies. However, the coins are mostly issued by centralized companies with their governance mechanisms, and in the case of full custody integration, they are vulnerable to fraud.

Besides, not all fiat currencies are stable, as their underlying fiat may not be stable themselves. For instance, the US dollar is backed by gold reserves whose value keeps on appreciating and depreciating. A consumer must have faith in the US dollar to use a USD backed stablecoin, like Tether, TrueUSD, USDCoin, and Gemini Dollar.

Crypto-collateralized

This type of stablecoins is backed by a class of other decentralized crypto-assets. The advantage of this collateralization method is that it is decentralized; hence, it is not susceptible to a central point of failure. The disadvantage is that despite their blend of assets thought to minimize volatility, in the current crypto markets influenced by whales, any combination of digital assets will be considered unstable.

The typical use case is MakerDAI. It managed to maintain its peg in 2018 despite an 80% decline in Ether’s value as the only collateral.

Non-collateralized

These stablecoins achieve stability through algorithms, implying that they are actually not pegged to any tangible asset. Instead, users trust the system, expecting that the coins will appreciate, just like Bitcoin. Non-collateralized stablecoins are designed with two protocols: a stablecoin and a bond, promising profits if the currency increases in value. By buying the bond with the stablecoin, its supply is reduced.

Non-collateralized coins are the most innovative stablecoins and also the most complex to thrive. A good example is the Basis Project. However, hybrids have been developed to leverage fiat and crypto-collateralized models, like the Reserve and Carbon coins.

Why are stablecoins important?

Stablecoins have undeniably steered in a new dawn, especially for early adopters of blockchain and crypto traders. As their stability continues to attract institutional investors and governments, more entrants are expected to join forces. This is how the stablecoin market looked from 2014 to 2019.

Their application has been embraced for various reasons, such as:

They encourage crypto adoption

The first digital currencies, like Bitcoin and Ethereum, were hard to comprehend and difficult to appreciate and adopt. Technical terminologies and explanations made many people think that they were for geeks only.

It was challenging to prove their application of buying goods and services in the real-world. However, stablecoins- particularly the fiat-collateralized model- are quite different. When you tell people that stablecoins are a type of digital currencies, it is easy to visualize them. Besides, since they are pegged to the value of real-world assets, such as the US Dollar, it is easy to trust and embrace them.

They calm volatility

As the term suggests, stablecoins are designed to have price stability. The main reason for their creation is to minimize price swings prevalent in mainstream cryptocurrencies. All the three types of stablecoins have shown a lot of potential. But, the fiat-collateralized stablecoins are the biggest winners so far. For example, a coin like Tether has already achieved much success in this regard.

Crypto-collateralized stablecoins have not yet been widely embraced because of the underlying issues with cryptocurrencies generally being highly volatile. It is, therefore, challenging to convince people that a coin will be stable, yet it’s pegged to unstable assets.

Value is straightforward

Stablecoins, particularly the fiat-collateralized ones, are easily valued. It is as easy as getting an account balance and using the dollar sign to comprehend or communicate the price. For instance, if you have 5,000 Gemini Dollars in your wallet, you basically have $5,000 in possession. The easy it is to value a digital asset, the easier it is to embrace them in day-to-day spending and cross-border payments. For instance, if you want to buy an iPhone valued at $1,500, you only need 1,500 USDT. This implies that to facilitate payment at the point of sale, only a stablecoin payment option is required for the retail outlets. Once developers consider such aspects, everything else will follow suit.

They are cost-effective and immediate

Being a blockchain-based form of money transfer, stablecoins bear many benefits of electronic money transfer, such as instant and cost-effective money transactions. Consider a situation where it costs you $4 to do a cross-border transaction. These charges cover labor costs, power bills, and audits for human error. Blockchain eliminates central entities automate manual tasks so you will only be charged about $1. Unlike bank transfers that take several hours to days to be completed, your transaction will be processed instantly. That is how JP Morgan is facilitating cross-border payments using their JPM Stablecoin .

The case for central bank digital currencies (CBDCs)

CBDCs have been a primary subject for blockchain enthusiasts, futurists, governments, and lawmakers for some time now. They have evolved from a topic of interest to a high-potential tool for governments to address better the severe economic effects of the Corona Virus and beyond. Lawmakers, including politicians and central banks, are uncertain where, how, and which tools to leverage to save their economies as they deal with the pandemic and prepare for the imminent. This has led to a heightened interest in crypto innovation for the coming decade.

Currently, the global economy requires a payment system with which you can make payments instantly, cost-effectively, and without intermediaries, like Visa and MasterCard. China is already piloting its “digital yuan,” with the US, Great Britain, France, South Korea, and other nations making tremendous efforts in developing their digital currencies backed by their native currencies.

Already 20% of the 66 banks have shown interest in issuing their digital currencies in the next ten years. With all these efforts happening quickly under closed doors, it appears inevitable that state-issued stablecoins will be prevalent in the next few years and eventually replace their fiat counterparts.

Conclusion

In general, stablecoins are revolutionary tools with huge potential to revolutionize the future of finance fundamentally. With blockchain as the underlying technology, they can scale rapidly globally and disrupt the traditional payment systems. Stablecoins are already thought-provoking people’s understanding of money, generating a paradox environment where they will thrive as the main currency.

Related posts:

Categories
Blockchain Financial Services Technology

Proof of work versus proof of stake: Comparing major consensus mechanisms

Consensus plays a crucial role in our day to day activities. Without it, we cannot make decisions on important issues affecting our countries, businesses, and families. Consider a scenario where there is a pressing issue to solve, and the whole nation lacks a mutual understanding. In such a scenario, lawmakers have to reason and come up with a mutual agreement to address the issue. There is no other democratic way around it.

The same principle applies to blockchain networks that use consensus mechanisms to enable participants to agree on various activities of a network, like transactions, forking, and voting. Without a consensus algorithm, a blockchain system cannot be an immutable database. Lack of consensus in a blockchain network would make the entire ecosystem of no use since miners or validators would be unable to process and verify transactions. I’ll compare and contrast the two major types of consensus mechanisms: proof-of-work and proof-of-stake. Before that, let’s define what a blockchain consensus algorithm is and the importance of a consensus mechanism.

Proof of work versus proof of stake: Comparing major consensus mechanisms

Table of contents:

What is a blockchain consensus algorithm?

A consensus algorithm enables members of a blockchain ecosystem to agree and commit new data to the blockchain. Consensus algorithms are essential for blockchain ecosystems since they lack central authorities. Because of the decentralized nature, nodes (also known as miners or validators) are responsible for maintaining blockchain systems through consensus algorithms. This ensures that participants conform to the set rules and regulations, achieving trustless transactions. In cryptocurrency transactions, this ensures that users can only spend their coins once.

The importance of consensus mechanisms

In this part, we will discuss the primary roles of consensus mechanisms to help us gain a better understanding of how blockchain algorithms work.
Facilitating a unified agreement : Centralized networks rely on third parties to run. But, consensus algorithms enable blockchain systems to operate without the need for members to trust each other. In other words, consensus algorithms achieve a unified agreement between network participants, ensuring that every transaction is valid and the database is up to date.
Aligning economic incentives : Since decentralized networks regulate themselves, it is vital to align the interests of the members/stakeholders to achieve optimal functionality. Consensus mechanisms employ economic incentives to reward users for proper conduct.
Ensuring fairness and equity : Consensus algorithms also ensure that justice and equity prevail among network users. Anyone can join an ecosystem — a public blockchain in this case — and all members should exercise equal voting rights.
Preventing doubles spending : Double spending is one of the major risks threatening digital payments as it affects the value of digital assets adversely, rendering them worthless in the long run. Consensus algorithms prevent double spending by guaranteeing that only verified and valid transactions make it into the public blockchain records.
Ensuring a fault-tolerant network : By warranting that a system is fault-tolerant, consistent, and dependable, a consensus algorithm enables a blockchain to continue functioning even in the face of severe threats and failures.

What is proof of work?

While the PoW mechanism existed way in the ’90s, Satoshi Nakamoto popularized the concept with the invention of Bitcoin in 2009. The Bitcoin network was the first significant use case of the PoW consensus mechanism. PoW is blockchain’s original consensus mechanism.
Early on in blockchain’s development, PoW was the most reliable method for blockchain consensus. It spearheaded the implementation of the decentralized vision and eliminated third-parties at the same time to guarantee valid network transactions. Nevertheless, as the technology continued to gain momentum, the drawbacks of this mechanism were increasingly apparent. Sometimes, it’s impossible to solve them.

How does proof of work function?

In PoW, miners must solve cryptographic puzzles to verify transactions. We can compare it to a race where runners are contending for an award. The race of this blockchain competition is referred to as a hash. For every confirmed transaction, miners are compensated with the network’s native cryptocurrency and a transaction fee.
It is important to note that blockchain puzzles are quite complex, and high computational power is needed to solve them. Below is a summary of the execution of the PoW consensus mechanism.
A new transaction is sent to a network.
Mining rigs begin to look for a hash value that aligns with that of the transaction.
The first to discover the hash gets a reward in cryptocurrency.
A new block is created, which comprises the recently completed transaction.
A section of each new hash bears the hash value of the last completed transaction in the block. This deters miners from confirming fraudulent transactions and the issue of double-spending. The complexity of a PoW puzzle is based on the number of nodes in a network. It is directly proportional to the computational power needed to solve it. This creates some severe consequences for a blockchain network using the PoW consensus mechanism. We will discuss these issues later with the proof-of-stake mechanism.

What is proof of stake?

As a result of the issues arising from the PoW mechanism, the blockchain developers started searching for a more economical method of reaching a consensus. Scott Nadal and Sunny King proposed the concept of proof of stake in 2012.
Currently, the Ethereum community is moving toward a PoS consensus mechanism through the Casper update. It aims to solve the problems of the PoW mechanism and those of PoS itself. For a comprehensive analysis concerning the Ethereum network developments, you can refer to this guide for more insights.
In proof of stake, computation power is replaced by currency power — the number of coins a node holds in its wallet. In a layman language, the ability to confirm a transaction depends on your network “stake.” Besides, miners are replaced by validators or forgers in PoS. Instead of mining coins in each transaction, all coins are minted by the developers during the network’s launch.

How does proof of stake work?

Instead of competing to be the first validator, the proof of stake mechanism picks a validator based on their stake in the blockchain. Assume you own tokens worth 25% of the block in your wallet, you will have the power to confirm 25% of the block only. When the Casper version launches, we will experience the reality of validator pools.
So far, we have learned what PoW and PoS are and how they function. Now, let us compare and contrast them.

Comparing PoW and PoS

There are concerns regarding the general security of the PoS protocol as it does not use real-world resources for validation. There is no cost required to create a new block on top of both branches in case of a temporary fork. This is a nothing at stake attack. On the other hand, PoW consumes electricity to mine blocks. Developers are still uncertain whether PoS protocols can offer the same security assurances over an extended period that Bitcoin, with its PoW mechanism, has provided for almost eleven years now.

Proof of work Proof of stake
  • Distributed consensus among untrusted and unknown nodes
  • Distributed consensus among untrusted and unknown nodes
  • Incentives are rewarded within the system for work done outside the system
  • Incentives are rewarded within the system for escrow inside the system
  • Relatively high cost of input with high returns
  • Low cost of input with low returns
  • Slow transaction rates
  • Fast transaction rates
  • Low efficiency that requires more power
  • High efficiency that requires less power

Another contrast between a proof of work and proof of stake protocol is that all validating nodes must be identifiable in a PoS protocol. The staked tokens are responsible for any network misconduct. On the other hand, a PoW mechanism does not require miners or nodes to be identifiable. As a matter of fact, it is a PoW aspect, that if a node receives a block, there are no further details regarding the miner of the block. What is essential is that the block and all its transactions are legit. You must trust the math to trust PoW.

Conclusion

Although proof of work protocols secure blockchain networks, it also negatively affects scalability and transaction output. Centralized establishments majorly run the PoW consensus mechanism, and its energy consumption is not sustainable.
While the proof of stake protocol offers less security, the validators use their own digital assets to the stake, forcing participants to have skin in the game. The mechanism also has recommendable scalability and transaction throughput.
The future of PoS relies on the up-and-coming shift of the Ethereum network. If the second biggest blockchain network can successfully transition to proof of stake and still exhibit the security of their ecosystem with the assistance of the novel Casper mechanism, it will convince the entire blockchain community about its power comparatively new Proof of Stake consensus mechanism.

Related posts:

Categories
Entrepreneurship Software

Project Management Checklist: Before You Start

Managing a project is no easy task. What makes it even harder is that if you omit or downplay an important step early on, the hurdles start mounting later. Our ‘starter’ checklist is designed to help you avoid such pitfalls and tricky situations. We’ve also made a checklist for ongoing projects to help you get organized.

Project management checklist: or the Project Starter

We’ll be honest: this project management checklist was first created for our internal use. However, we’ve decided there’s too much solid advice for it to stay on Google Drive. Because we know this works. It’s based on years of our PM experience. After all, there’s more to a real software house than just code! Great project managers deserve ‘ninja’ and ‘rockstar’ titles of their own.

The “project starter” is our guarantee that the project will be kicked off in the best way possible, and no important issue will be omitted. The list has been divided into several fields, though there is a chronological feel to it as well, the sequence is not necessarily set in stone.

We’ll be returning to this topic with another checklist! Next time, we’ll talk about what boxes you need to tick off with an ongoing project. Meanwhile, don’t forget to check our other agile and management resources.

What tips do you have for project management, especially at early stages? Let us know in the comments!

See also: