<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sonu sharma</title>
    <description>The latest articles on DEV Community by sonu sharma (@sonu_sharma).</description>
    <link>https://dev.to/sonu_sharma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F179826%2F0c8f3be2-e953-481a-af1a-ec553360e8c0.jpg</url>
      <title>DEV Community: sonu sharma</title>
      <link>https://dev.to/sonu_sharma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sonu_sharma"/>
    <language>en</language>
    <item>
      <title>Security of Blockchain Transactions vs. REST API Calls</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Thu, 19 Sep 2024 18:25:28 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/security-of-blockchain-transactions-vs-rest-api-calls-5fna</link>
      <guid>https://dev.to/sonu_sharma/security-of-blockchain-transactions-vs-rest-api-calls-5fna</guid>
      <description>&lt;h3&gt;
  
  
  REST API Calls
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Centralized&lt;/strong&gt;: Typically, REST APIs are centralized, meaning they are controlled by a single entity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: The security of REST API calls depends on the implementation. Common security measures include authentication, encryption, and input validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trust&lt;/strong&gt;: Users must trust the entity controlling the API to handle their data securely and fairly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blockchain Transactions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Decentralized&lt;/strong&gt;: Blockchain transactions are decentralized, meaning they are not controlled by a single entity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: The security of blockchain transactions is ensured through cryptographic algorithms and consensus mechanisms. Each transaction is verified by multiple nodes in the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutability&lt;/strong&gt;: Once a transaction is confirmed and added to the blockchain, it cannot be altered or deleted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transparency&lt;/strong&gt;: All transactions are publicly visible on the blockchain, ensuring transparency and accountability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Answering the Question:
&lt;/h3&gt;

&lt;p&gt;When someone asks how blockchain transactions are secure compared to REST API calls, you can explain the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decentralization&lt;/strong&gt;: Blockchain transactions are decentralized, meaning they are not controlled by a single entity. This reduces the risk of fraud and tampering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cryptographic Security&lt;/strong&gt;: Blockchain transactions are secured using cryptographic algorithms, ensuring that only the intended recipient can access the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consensus Mechanisms&lt;/strong&gt;: Blockchain transactions are verified by multiple nodes in the network, ensuring that they are valid and secure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immutability&lt;/strong&gt;: Once a transaction is confirmed and added to the blockchain, it cannot be altered or deleted. This ensures the integrity of the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transparency&lt;/strong&gt;: All transactions are publicly visible on the blockchain, ensuring transparency and accountability.&lt;/p&gt;

&lt;p&gt;In contrast, REST API calls are centralized and rely on the security measures implemented by the entity controlling the API. While REST APIs can be secure, they do not offer the same level of decentralization, transparency, and immutability as blockchain transactions.&lt;/p&gt;

&lt;p&gt;This post is AI generated, I take credit for the question whose AI answer I have copied here 🫶&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>learning</category>
      <category>explainlikeimfive</category>
    </item>
    <item>
      <title>Not an ideal notification service ?</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Thu, 19 Sep 2024 17:35:13 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/not-an-ideal-notification-service--a12</link>
      <guid>https://dev.to/sonu_sharma/not-an-ideal-notification-service--a12</guid>
      <description>&lt;h3&gt;
  
  
  Expected notificaiton service 🚀
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqmempvzh24zs468oqdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqmempvzh24zs468oqdl.png" alt="A scalable notification service" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
This is what I would build as a notification service. This notification service would take care of all the ideal functional and non-funcitonal desing requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  The startup's notification service 😎
&lt;/h3&gt;

&lt;p&gt;But this is what I end up building. &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffq9iqfnktlfb1vm47gfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffq9iqfnktlfb1vm47gfx.png" alt="Startup's notification" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How is your notification service built ?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>softwaredevelopment</category>
      <category>microservices</category>
      <category>architecture</category>
    </item>
    <item>
      <title>ACID Transactions</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Sat, 07 Sep 2024 07:40:30 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/acid-transactions-3em8</link>
      <guid>https://dev.to/sonu_sharma/acid-transactions-3em8</guid>
      <description>&lt;p&gt;ACID Transactions&lt;/p&gt;

&lt;p&gt;What is a Transaction any way ?&lt;/p&gt;

&lt;p&gt;A transaction is a group of SQL commands whose results will be made available to the rest of the system as a unit when the transaction commits or not at all, if the transaction aborts.&lt;/p&gt;

&lt;p&gt;Transactions are expected to be ACID.&lt;/p&gt;

&lt;p&gt;ACID, an acronym for Atomicity, Consistency, Isolation and Durability defines a set of properties that ensure database transactions are processed reliably.&lt;/p&gt;

&lt;p&gt;ACID is most often associated with transactions on a single database server, but &lt;code&gt;distributed transactions&lt;/code&gt; extend that guarantee across multiple databases. &lt;/p&gt;

&lt;p&gt;I found a good article on distributed transaction and it implementation  - &lt;a href="https://hazelcast.com/glossary/distributed-transaction/" rel="noopener noreferrer"&gt;https://hazelcast.com/glossary/distributed-transaction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some databases may not support distributed transactions like postgresql do not support distributed transactions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can you nest transactions ?
&lt;/h3&gt;

&lt;p&gt;I would suggest read this article by Brent Ozar - &lt;a href="https://www.brentozar.com/archive/2023/02/can-you-nest-transactions-in-sql-server/" rel="noopener noreferrer"&gt;https://www.brentozar.com/archive/2023/02/can-you-nest-transactions-in-sql-server/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s see ACID properties one by one.
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Atomicity&lt;/strong&gt;: Atomicity ensures set of transaction is treated as an individual unit of work. It means either all the operations are successful or none of them are applied to the database.&lt;/p&gt;

&lt;p&gt;If any of part of the transaction fails, the entire transaction is rolled back, and the database is restored to its previous consistent state.&lt;/p&gt;

&lt;p&gt;Example : In a banking transaction Atomicity ensures either both credit and debit operation occur, or neither does.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt; &lt;span class="n"&gt;TRANSACTION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;UPDARE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Consistency ensures that a transactions brings the database from one valid state to another valid state. It means all the data integrity constraints such as foreign key, check constraints are satisfied before and after the transactions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Isolation&lt;/strong&gt;: Isolation ensures that transactions are executed in a way that they do not interfere with each other means the intermediate state of one transaction is invisible to another parallel transaction.&lt;/p&gt;
&lt;h4&gt;
  
  
  Isolation levels:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Read Uncommitted&lt;/strong&gt;: Transactions can see uncommitted changes from other transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Read Committed&lt;/strong&gt;: Transactions can only see committed changes from other transactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repeatable Read&lt;/strong&gt;: Ensures that if a transactions read a row, it will read the same row consistently during its entire execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Serializable&lt;/strong&gt;: Provides the highest level of isolation, ensuring transactions are executed serially.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Check Isolation Level in Postgresql&lt;/span&gt;

&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="n"&gt;default_transaction_isolation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- output : `read committed`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Here is good read on ACID implementation in Posgresql - &lt;a href="https://www.postgresql.org/files/developer/transactions.pdf" rel="noopener noreferrer"&gt;https://www.postgresql.org/files/developer/transactions.pdf&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Durability&lt;/strong&gt;: it ensures that once a transaction is committed, it will remains so, even in the event of a system failure. This means that committed data will not be lost.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;ACID transaction has 4 phases &lt;code&gt;Begin Transaction&lt;/code&gt; , &lt;code&gt;Execute Transaciton&lt;/code&gt; , &lt;code&gt;Commit Transaction&lt;/code&gt; , &lt;code&gt;Rollback Transaction&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Databases implement ACID transactions through a combination of techniques, including
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Logging&lt;/strong&gt;: Detailed records of all the transactions are kept, allowing for recovery in case of failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Locking&lt;/strong&gt;: Data is locked during a transaction to prevent concurrent access and ensure isolation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tow-Phase Commit&lt;/strong&gt;: A protocol used to coordinate the commitment of a transaction across multiple systems.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are lot of techniques to implement transactions and use cases where transactions are used. At present it is a fundamental concept in database management systems that ensure data integrity, reliability and consistency.&lt;/p&gt;

&lt;p&gt;By understanding and leveraging ACID transactions, developers can deliver a reliable and predictable applications.&lt;/p&gt;




&lt;p&gt;Thank you so much for reading. ❤️&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>performance</category>
      <category>learning</category>
    </item>
    <item>
      <title>CAP Theorem</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Thu, 29 Aug 2024 03:54:51 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/cap-theorem-11kp</link>
      <guid>https://dev.to/sonu_sharma/cap-theorem-11kp</guid>
      <description>&lt;p&gt;It is a fundamental framework for understanding trade-offs when designing distributed systems.&lt;/p&gt;

&lt;p&gt;Consistency (C): A distributed system is said to be highly consistent when every read receives the most recent write or an error.&lt;/p&gt;

&lt;p&gt;Availability (A): A distributed system is said to be highly Available when every request (Read or Write) receives a non-error response, without guarantee that it contains the most recent write&lt;/p&gt;

&lt;p&gt;Partition Tolerance (PT): A highly partition tolerant system continues to operate despite an arbitrary number of messages drop(delay) between nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The CAP trade-off: Choosing 2 of 3&lt;/strong&gt;: In the presence of network partition a distributed system must choose between Consistency or and Availability.&lt;/p&gt;

&lt;p&gt;CP (Consistency and Partition Tolerance): During a partition, the system may reject some requests to maintain consistency.&lt;/p&gt;

&lt;p&gt;AP (Availability and Partition Tolerance): During a partition, different nodes may return different values for the same data.&lt;/p&gt;

&lt;p&gt;CA (Consistency and Availability): In the absence of partitions, a system can be both consistent and available. However the network partition are inevitable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Practical strategies
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Eventual consistency: This gives a good balance where an immediate consistency is not necessary like CDNs and DNS, eventually these will be updated with latest data.&lt;/li&gt;
&lt;li&gt;Strong consistency: Financial applications can work with eventual consistency they need a strong consistency.&lt;/li&gt;
&lt;li&gt;Tuneable consistency: Allows systems to adjust their consistency levels based on specific needs. Systems like Cassandra allow configuring the level of consistency on a per-query basis.&lt;/li&gt;
&lt;li&gt;Quorum-Based Approaches: Use voting system among a group of nodes to ensure a certain level of consistency.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Comment the interesting ways you use this theorem.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>learning</category>
      <category>development</category>
    </item>
    <item>
      <title>Scalability</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Wed, 28 Aug 2024 03:37:11 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/scalability-3pl4</link>
      <guid>https://dev.to/sonu_sharma/scalability-3pl4</guid>
      <description>&lt;p&gt;Scalability is the property of system to evolve as the work load grows.&lt;/p&gt;

&lt;p&gt;Types of work load&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Users&lt;/li&gt;
&lt;li&gt;New features&lt;/li&gt;
&lt;li&gt;Data volume&lt;/li&gt;
&lt;li&gt;Complexity in code&lt;/li&gt;
&lt;li&gt;Geographical Reach&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ways to scale your system&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Vertical scaling (Scale up) : adding more RAM / fast ram, it is effective but has limit to how effective it can be.&lt;/li&gt;
&lt;li&gt;Horizontal scaling (Scale out) : adding additional machines to distribute work on these new added machines to reduce work load on a single machine.&lt;/li&gt;
&lt;li&gt;Partitioning: Split the data across multiple nodes to distribute workload and avoid bottlenecks.&lt;/li&gt;
&lt;li&gt;Load Balance: Having a lot of machines running is ineffective if the traffic is on single machine. Here comes load balances to distribute the traffic across machines.&lt;/li&gt;
&lt;li&gt;Auto Scaling: Helps to automatically spin new machines when burst of traffic apprears.&lt;/li&gt;
&lt;li&gt;Caching: Go to mechanism to improve latency of APIs. It is effective in reducing load on databases.&lt;/li&gt;
&lt;li&gt;Content Delivery Network (CDNs): Used to serve static pages, images, videos results in faster load time.&lt;/li&gt;
&lt;li&gt;Asynchronous Communication: Defer long-running tasks / non-critical tasks to background queues or message brokers. This ensures your main application remains responsive to users.&lt;/li&gt;
&lt;li&gt;Microservices Architecture: Break down your service to small independent services so that these services can scaled independently.&lt;/li&gt;
&lt;li&gt;Multi-region Deployment: Deploy the application in multiple data centers or cloud regions to reduce latency and improve redundancy.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>systemdesign</category>
      <category>devjournal</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Availability</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Wed, 28 Aug 2024 03:34:24 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/availability-bj0</link>
      <guid>https://dev.to/sonu_sharma/availability-bj0</guid>
      <description>&lt;p&gt;Availability is defined as the proportion of time a system is up and serving the traffic. It is defined in terms of percentage. Can also be divided into tiers of 2 nines (99%), 3 nines (99.9%), 4 nines (99.99%), 5 nines (99.999%) and 6 nines (99.9999 %).&lt;/p&gt;

&lt;h3&gt;
  
  
  Ways to improve Availability
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Redundancy : It is a way of having backup components which can takeover when primary components fail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technique to Add Redundancy&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Server Redundancy: Having multiple instance of the same server helps in distributing traffic across servers, ensuring if one fails other can provide service.&lt;/li&gt;
&lt;li&gt;Database Redundancy: Creating a replica database that can takeover when primary database fails.&lt;/li&gt;
&lt;li&gt;Geographic Redundancy: Distributing resources across multiple geographic locations to solve/mitigate the regional failures&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Load Balancing: It distributes the incoming traffic across multiple servers to ensure that no single server becomes a bottleneck this improving performance and availability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technique to Add Load Balancing&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hardware Load Balancing: Physical devices that distributes traffic based on preconfigured rules.&lt;/li&gt;
&lt;li&gt;Software Load Balancing: Software solutions that manage traffic distribution. Solutions like HAProxy, Nginx, or cloud-based solution like AWS Elastic Load Balancer.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Data Replication: It is a way of copying data to multiple locations either asynchronously or in realtime ensuring data is available even one location fails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technique of Data Replication&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Synchronous Replication: Data is replicated in real-time to ensure consistency across location.&lt;/li&gt;
&lt;li&gt;Asynchronous Replication: Date is replicated with delay, which can be more efficient but may result in slight data inconsistencies. &lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Failover Mechanism: Failover mechanism automatically witches to redundant system when a failure detected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Techniques of Failover Mechanism&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Active-Passive failover mechanism: A primary active component is backed by a passive standby component that takes over upon failure.&lt;/li&gt;
&lt;li&gt;Active-Active failover mechanism: All components are active and share the load. If one fails, remaining components continue to handle the load seamlessly.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Monitoring &amp;amp; Alerts: Continuous health monitoring involves checking the status of the system components to detect failures early and trigger alert for immediate action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Techniques for Monitoring &amp;amp; Alerts&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Heartbeat Signals: Regular signals sent between components to check their status.&lt;/li&gt;
&lt;li&gt;Health Check: Automated scripts or tools that perform regular check on components.&lt;/li&gt;
&lt;li&gt;Alerting systems: Tools like PagerDuty or OpsGenie that notify administrators of any issues.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;h3&gt;
  
  
  Best practices for Availability
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Build for failure: Assume that components can go down at any moment and build the required fall back mechanisms&lt;/li&gt;
&lt;li&gt;Implement Health Check&lt;/li&gt;
&lt;li&gt;Use Multiple availability zones: Distribute the system across multiple data centers to prevent localized failures.&lt;/li&gt;
&lt;li&gt;Practice chaos Engineering: Check reliability by intentionally introducing failures.&lt;/li&gt;
&lt;li&gt;Implement Circuit Breakers: Prevent cascading failures by quickly cutting off problematic services&lt;/li&gt;
&lt;li&gt;Use caching wisely: Caching can reduce load on databases.&lt;/li&gt;
&lt;li&gt;Plan for capacity: Ensure your system can handle both expected and unexpected loads.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The System Design diary</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Tue, 27 Aug 2024 02:28:05 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/the-system-design-diary-4ijm</link>
      <guid>https://dev.to/sonu_sharma/the-system-design-diary-4ijm</guid>
      <description>&lt;h2&gt;
  
  
  Dev diary
&lt;/h2&gt;

&lt;p&gt;I will be posting my learnings on system design.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>seniorsoftware</category>
      <category>learning</category>
    </item>
    <item>
      <title>Revolutionise Authentication using Hanko</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Wed, 25 Oct 2023 20:22:31 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/revolutionise-authentication-using-hanko-2194</link>
      <guid>https://dev.to/sonu_sharma/revolutionise-authentication-using-hanko-2194</guid>
      <description>&lt;h2&gt;
  
  
  Hanko Memes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is an AI-based fun project which lets anyone create memes.&lt;/li&gt;
&lt;li&gt;This project is part of a hackathon to create any functioning app that can be hosted online with Hanko auth integrated.&lt;/li&gt;
&lt;li&gt;In this project OpenAI chat completion model generates a caption given a topic and audience.&lt;/li&gt;
&lt;li&gt;Once the caption is generated user can use a meme template to add the generated caption thus producing a sharable meme.&lt;/li&gt;
&lt;li&gt;Technologies: NextJs, Hanko Authentication, Supabase, ui.shadcn , Deployed on Netlify and Vercel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Working Application : &lt;a href="https://hanko-memes.vercel.app"&gt;https://hanko-memes.vercel.app&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Just clone [hanko-memes](&lt;a href="https://github.com/sonu0702/"&gt;https://github.com/sonu0702/&lt;/a&gt; repo
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Install all packages
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   yarn &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  .env file , generate your &lt;a href="https://docs.hanko.io/setup-hanko-cloud"&gt;hanko api url&lt;/a&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   copy content of .env.example into .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the server
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application connects with the backend server deployed on Netlify.&lt;br&gt;
You can find the code in &lt;a href="https://github.com/sonu0702/hanko-memes-be"&gt;hanko-memes-be&lt;/a&gt;&lt;br&gt;
If you want to check out just the frontend integration of &lt;br&gt;
Hanko Authentication just check my frontend repo &lt;a href="https://github.com/sonu0702/hanko-memes"&gt;hanko-memes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the frontend integration of the Hanko Authentication, I used &lt;a href="https://github.com/teamhanko/hanko-nextjs-starter"&gt;hanko-nextjs-starter&lt;/a&gt;. It is very helpful and I would recommend this since it will give a clear picture of the authentication flow. The other which developers have is &lt;a href="https://docs.hanko.io/quickstarts/frontend/react"&gt;Hanko documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So Hanko is a hands-down winner in enhancing experience user authentication and security.&lt;br&gt;
This is my first time using a biometric authentication integration into a web application and Hanko made it very simple.&lt;/p&gt;
&lt;h2&gt;
  
  
  Application using Hanko
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Login
&lt;/h3&gt;

&lt;p&gt;This is the interface of login for users, they can login in using email or passkey, which will open an interface to use the finger biometric of your device,&lt;br&gt;
in my case laptop.&lt;/p&gt;

&lt;p&gt;Meme template, MyMemes and Generate meme are other features which I have added.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NbHkOVc1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/ac5df68e-c2b3-41c2-bd06-add839ebd00f" class="article-body-image-wrapper"&gt;&lt;img alt="Hanko login Interface" src="https://res.cloudinary.com/practicaldev/image/fetch/s--NbHkOVc1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/ac5df68e-c2b3-41c2-bd06-add839ebd00f" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Meme Templates
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Meme Template&lt;/code&gt; page lists all the meme templates which a user can use to write captions and personalise the meme.&lt;/p&gt;

&lt;p&gt;Once you click on any of the Memes you will be redirected to the &lt;code&gt;Meme Generator&lt;/code&gt; page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cxxx1-3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/494cf191-e483-4c87-a092-a73a2b2499bb" class="article-body-image-wrapper"&gt;&lt;img alt="Meme Templates" src="https://res.cloudinary.com/practicaldev/image/fetch/s--cxxx1-3b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/494cf191-e483-4c87-a092-a73a2b2499bb" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Meme Generator
&lt;/h3&gt;

&lt;p&gt;This is the most interesting feature actually. You just have to fill in Topic and Audience as shown in the screenshot and click on &lt;code&gt;AI Captions&lt;/code&gt;, AI will generate captions for you.&lt;br&gt;
or you can just type in top and bottom captions and then click on Generate Meme to create a shareable meme.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qQabcKXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/6dfb34c2-fef6-41ea-bf4d-90718c430177" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--qQabcKXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/6dfb34c2-fef6-41ea-bf4d-90718c430177" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  My Memes
&lt;/h3&gt;

&lt;p&gt;Since you are logged into the application, the application stores the memes generated by you to be visible only to you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RbwN2Ge1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/a11b7f24-85e1-45a2-bd3f-9624a3503f0e" class="article-body-image-wrapper"&gt;&lt;img alt="image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--RbwN2Ge1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/sonu0702/hanko-memes/assets/61102795/a11b7f24-85e1-45a2-bd3f-9624a3503f0e" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Backend Integration of Hanko Auth
&lt;/h2&gt;

&lt;p&gt;I have my backend code in &lt;a href="https://github.com/sonu0702/hanko-memes-be"&gt;hanko-memes-be&lt;/a&gt;. The most significant peace of code which I want to briefly touch upon is how to handle / very Hanko Auth Token.&lt;/p&gt;

&lt;p&gt;Let me paste the code here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonwebtoken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;jwksClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jwks-rsa&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nl"&gt;authenticatedUserId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorization&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bearer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwksClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;jwksUri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;HANKO_API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/.well-known/jwks.json`&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;signkey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSigningKey&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;publicKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signkey&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPublicKey&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;publicKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;verified&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Invalid user`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is as simple as it looks. Hanko has followed JWT token standards for user authentication.&lt;/p&gt;

&lt;p&gt;I have used standard &lt;code&gt;jsonwebtoken&lt;/code&gt; and &lt;code&gt;jwks-rsa&lt;/code&gt; libraries. These libraries helped me get the public key using that I have verifed the JWT token to extract userId.&lt;/p&gt;

&lt;p&gt;By participating in &lt;a href="https://www.hanko.io/hackathon#Apply"&gt;hanko hackathon&lt;/a&gt; hackathon I got to explore Hanko Authentication an awesome authentication library, OpenAI to generate meme captions and Next.Js 13.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>hanko</category>
      <category>openai</category>
      <category>memes</category>
    </item>
    <item>
      <title>Authentication is hard. Let FACEIO handle it for you</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Sun, 04 Dec 2022 07:01:11 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/authentication-is-hard-let-faceio-handle-it-for-you-140c</link>
      <guid>https://dev.to/sonu_sharma/authentication-is-hard-let-faceio-handle-it-for-you-140c</guid>
      <description>&lt;p&gt;There are very few companies which implement their own authentication system. This is because even big and advanced companies can fall prey to security attacks. This leads to awkward lawsuits and in some cases company's downfall. &lt;/p&gt;

&lt;p&gt;Authentication systems are developed as components in a complex application or as a service. If the company is developing the authentication system for providing identity as a service then it makes sense to spend time and resources. But if it is being used as one of the components in a complex application then even the big and advanced companies try to use what is already tried and tested. This approach not only saves time and money but it will provide much-needed security for such an important component.&lt;/p&gt;

&lt;p&gt;Developers have been developing and optimising the authentication system for a long time now. It is still a complex feature which needs dedicated time and resources. Handling user data is probably one of the most complex parts to get right in any application (web or not). There are just so many places for something to go wrong. It becomes really hard to ensure that your app is really secure.&lt;/p&gt;

&lt;p&gt;It’s not just login form -&amp;gt; check username/password -&amp;gt; set the cookie. It has a lot of other things to think about:&lt;/p&gt;

&lt;p&gt;Cookie security, Password requirements, Storing passwords in the database, Email vs username, Rate-limiting authentication attempts, Captcha, Password reset, 2FA, Force 2FA by admin configuration and whatnot.&lt;/p&gt;

&lt;p&gt;This is why it is essential that you follow the latest best practices when designing an authentication system for your web application. Better yet, you could get someone more experienced to do it for you while you focus on the core features of your app.&lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://faceio.net/" rel="noopener noreferrer"&gt;FACEIO&lt;/a&gt; comes in handy. In this case FACEIO “someone more experienced” will take care of authentication for us.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://faceio.net/" rel="noopener noreferrer"&gt;FACEIO&lt;/a&gt;, you can leverage the experience of some of the smartest minds in software development to build an authentication system that has been battle tested for years and vetted by the pros in the industry.&lt;/p&gt;

&lt;p&gt;FACEIO is a facial authentication framework that is to be implemented on websites or web applications via a simple JavaScript snippet. It authenticates users using face recognition instead of the traditional login/password pair or OTP code. It is a cross-browser, Cloud  &amp;amp; On-Premise deployable.&lt;/p&gt;

&lt;p&gt;In my opinion, it is the easiest way to add passwordless authentication to websites or web applications. Simply &lt;a href="https://faceio.net/integration-guide" rel="noopener noreferrer"&gt;implement&lt;/a&gt; &lt;code&gt;fio.js&lt;/code&gt; on your website, and you will be able to &lt;strong&gt;instantly authenticate your existing users, and enroll new ones via Face Recognition&lt;/strong&gt; using their computer Webcam or smartphone frontal camera on their favourite browser.&lt;/p&gt;

&lt;p&gt;Enough of theory, let me show you a working demo on how to integrate and use FACEIO facial authentication in a reactJS application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwks09v0uxlsopsjtkll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbwks09v0uxlsopsjtkll.png" alt="folder structure" width="786" height="478"&gt;&lt;/a&gt;&lt;br&gt;
This is the folder structure of my ReactJS application which I am going to use for FACEIO demo.&lt;/p&gt;

&lt;p&gt;The first step in integration after setting up a ReactJS project is to integrate fio.js cdn within the public/index.html file as shown in the following section&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt;
      &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt;
      &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1, shrink-to-fit=no"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"theme-color"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"#000000"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!--
      manifest.json provides metadata used when your web app is added to the
      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
    --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"manifest"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"%PUBLIC_URL%/manifest.json"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"shortcut icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"%PUBLIC_URL%/favicon.ico"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;React App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;noscript&amp;gt;&lt;/span&gt;
      You need to enable JavaScript to run this app.
    &lt;span class="nt"&gt;&amp;lt;/noscript&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.faceio.net/fio.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the &amp;lt;body&amp;gt; tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see I have added facio cdn link - &lt;code&gt;https://cdn.faceio.net/fio.js&lt;/code&gt; within the &lt;code&gt;&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; tag in &lt;code&gt;index.html&lt;/code&gt; file like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.faceio.net/fio.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second part is easier than the first one. You just have to invoke either enroll() function to sign up new users for your application or invoke authenticate()  function to sign in already authenticated users.&lt;/p&gt;

&lt;p&gt;I have done this in my App.js file. But you are free to do it in any file. Let add the code snippet for you for better understanding.&lt;br&gt;
src/App.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;handleError&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./errorHandler&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;faceio&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;faceid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFaceId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;accountExistString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setAccountExistString&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;faceio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;faceIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;application-id&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setAccountExistString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;faceid&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleNewUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;faceio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enroll&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nf"&gt;setFaceId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;facialId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;handleError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setAccountExistString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your account exists, Please Sign In&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setAccountExistString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Something went wrong! Please try again!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is done&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleAuthentication&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;faceio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nf"&gt;setFaceId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;facialId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleLogout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reload&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;faceid&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./padlock.svg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;faceid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;300&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Face&lt;/span&gt; &lt;span class="nx"&gt;Identity&lt;/span&gt; &lt;span class="nx"&gt;Verified&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mybutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleLogout&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nx"&gt;Logout&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;faceid&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;Verify&lt;/span&gt; &lt;span class="nx"&gt;Face&lt;/span&gt; &lt;span class="nx"&gt;Identity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./faceid.svg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;faceid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;300&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;200&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mybutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleAuthentication&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nx"&gt;Sign&lt;/span&gt; &lt;span class="nx"&gt;In&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mybutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleNewUser&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nx"&gt;Sign&lt;/span&gt; &lt;span class="nx"&gt;Up&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;accountExistString&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;accountExistString&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h3&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are three important things happening here &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialise your faceio application using &lt;code&gt;&amp;lt;application-id&amp;gt;&lt;/code&gt;. Application id you get by signing up &lt;a href="https://console.faceio.net/" rel="noopener noreferrer"&gt;FACEIO&lt;/a&gt; .&lt;/li&gt;
&lt;li&gt;Onclick event handling for Sign In and Sign Up buttons. On Sign Up, I am invoking the following enroll() function of fio.js . And on Sign In, I am invoking authenticate() function to sign in enrolled users. I would suggest you go through the &lt;a href="https://faceio.net/integration-guide" rel="noopener noreferrer"&gt;integration&lt;/a&gt; documentation to better understand the use of fio.js. &lt;/li&gt;
&lt;li&gt;Handling errors from fio.js. I am handling all type errors from fio.js. You can find the error codes and their description in the following fio.js documentation. &lt;a href="https://faceio.net/integration-guide#error-codes" rel="noopener noreferrer"&gt;fio.js error codes&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the full code, you can clone my &lt;code&gt;faceiodemo&lt;/code&gt; GitHub repo using &lt;a href="https://github.com/sonu0702/faceiodemo.git" rel="noopener noreferrer"&gt;https://github.com/sonu0702/faceiodemo.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the preview of my demo app which I have deployed on &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;vercel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://csb-kwbgjs-nq8tfdpqc-sonu0702.vercel.app/" rel="noopener noreferrer"&gt;https://csb-kwbgjs-nq8tfdpqc-sonu0702.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://faceio.net/" rel="noopener noreferrer"&gt;FACEIO&lt;/a&gt; takes care of that too. If you tried my demo application you would know that once the face recognition is done you will require to input a PIN. This pin combined with facial recognition will be used to authenticate you.&lt;/p&gt;

&lt;p&gt;As a developer, I can say that overall FACEIO gives a hassle-free frontend development experience. Frontend developers do not have to worry about creating a form, handling form errors and all other things which we have been dealing with for so long. For backend developers, &lt;a href="https://faceio.net/" rel="noopener noreferrer"&gt;FACEIO&lt;/a&gt; gives webhook events on creating new users. These events can be listened to and stored to authenticate other API flows of the application.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>How to use Redis pub/sub to handle socket.io sessions across multiple instances ?</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Fri, 09 Sep 2022 02:36:19 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/how-to-use-redis-pubsub-to-handle-socketio-sessions-across-multiple-instances--3f3o</link>
      <guid>https://dev.to/sonu_sharma/how-to-use-redis-pubsub-to-handle-socketio-sessions-across-multiple-instances--3f3o</guid>
      <description>&lt;p&gt;When we use socket.io we are generally trying to publish messages to all the collaborators of the workspace in an application even though the origin of the message was one of the collaborator specially in a collaborative application.&lt;/p&gt;

&lt;p&gt;In this scenario where a server must convey its message to multiple users, a socket client creates a room and adds users to this room. when any change (like app update , new comment) happens in this room that particular change must be conveyed to all the members of the room.&lt;/p&gt;

&lt;p&gt;The information, that there is a room called &lt;code&gt;xyz&lt;/code&gt; and there are some collaborators say a, b, c in the room is stored by a socket instance on a particular server instance.&lt;/p&gt;

&lt;p&gt;When multiple instances of the application or server are created a new instance of socket is also created for the new instance of application. Now, when the changes of a room comes to this server this instance does not know about the room created by previous instance and also does not know about the members / collaborators of the room. Therefore new server instance can’t send the changes to those connected to the existing server. I have tried to explain the problem visually here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpbzqtvadct0elitt94v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpbzqtvadct0elitt94v.png" alt="The problem"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before going into the solution of the problem, let’s understand the technologies i have used along with some snippet of the actual &lt;a href="https://github.com/sonu0702/redis-socket-blog/tree/master" rel="noopener noreferrer"&gt;code&lt;/a&gt;. I have written the server code in &lt;a href="https://go.dev/learn/" rel="noopener noreferrer"&gt;golang&lt;/a&gt; and i am using &lt;a href="https://www.postman.com/" rel="noopener noreferrer"&gt;Postman&lt;/a&gt; as client. The two technologies i would like to brief you all are &lt;a href="http://socket.io" rel="noopener noreferrer"&gt;socket.io&lt;/a&gt; and &lt;a href="https://redis.io/docs/manual/pubsub/" rel="noopener noreferrer"&gt;Redis pub/sub&lt;/a&gt;.&lt;br&gt;
If you are already familiar with the concepts just glance through my description to better understand the blog and solution provided by it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Brief description on socket.io
&lt;/h3&gt;

&lt;p&gt;Socket.io helps in delivering messages to client in real time. Behind the scene &lt;a href="http://socket.io" rel="noopener noreferrer"&gt;socket.io&lt;/a&gt; creates a bi-directional channel between server and client therefore enabling bidirectional communication between web client and server. For &lt;a href="https://github.com/sonu0702/redis-socket-blog/tree/master" rel="noopener noreferrer"&gt;demo code&lt;/a&gt; I have used a &lt;a href="https://go.dev/learn/" rel="noopener noreferrer"&gt;golang&lt;/a&gt; server therefor i have used a golang library called &lt;a href="https://github.com/googollee/go-socket.io/tree/master/_examples" rel="noopener noreferrer"&gt;go-socket.io&lt;/a&gt; . Some advance socket.io concepts which you should be aware are channel, event, namespace and rooms.&lt;/p&gt;

&lt;p&gt;Golang code snippet for Connecting to a socket.io - find full code &lt;a href="https://github.com/sonu0702/redis-socket-blog/tree/master" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SocketServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OnConnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;socketio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Conn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"connected:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Golang code snippet for Disconnecting from a socket.io&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SocketServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OnDisconnect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;socketio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Conn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Disconnected "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="s"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Leave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Disconnected "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Brief description on rooms in socket.io
&lt;/h3&gt;

&lt;p&gt;Room is a &lt;a href="http://socket.io" rel="noopener noreferrer"&gt;socket.io&lt;/a&gt; feature. By using this a server can send a message to a particular group/subscribers. In order for the clients to receive the messages of particular group they have be subscribed/joined to a particular namespace called room. Then the socket.io uses broadcast method of the socket object to send messages to all the subscribed clients.&lt;/p&gt;

&lt;p&gt;Socket.io rooms can be used in Chat applications and application which use workspace and collaborator architecture. In chat application the message is broadcasted to the group and all the users of the group receive the message in real-time. In collaborative applications messages are broadcasted to a workspace so that collaborators can receive them. Here is pictorial view explaining concept of rooms in socket.io.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9xnxhodg21ljtig1n0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl9xnxhodg21ljtig1n0l.png" alt="socket.io room"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Golang code snippet explaining the room join functionality&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SocketServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OnEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"application"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authorize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;socketio&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Conn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="n"&gt;ApplicationSubscriptionPayload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"roomName : "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;getRoomName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WorkspaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="s"&gt;"payload : "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;roomName&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;getRoomName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WorkspaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Event&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;Subscribe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;sessionContext&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;getSessionContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;roomName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"subscribed : (%s), sessionId : %s, roomName : %s , allRooms : %v "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;sessionContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
                    &lt;span class="n"&gt;roomName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rooms&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                &lt;span class="n"&gt;newApplicationSubscriptionResponse&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;NewApplicationSubscriptionResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SUCCESS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"application_response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newApplicationSubscriptionResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%s un subscribed to roomName : %s , allRooms : %v "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;roomName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Rooms&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Leave&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;getRoomName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WorkspaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppId&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="n"&gt;newNodezapSubscriptionResponse&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;NewApplicationSubscriptionResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SUCCESS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"application_response"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newNodezapSubscriptionResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
        &lt;span class="p"&gt;})))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the given code snippet authenticate, authorize functions are optional. These functions are middleware which can be used to add some more context to the event. &lt;code&gt;s.Join(roomName)&lt;/code&gt; function is used to join the given room name. &lt;/p&gt;

&lt;p&gt;A sample payload which can be used to join the room is as given below it is specific to the application I have written.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"event"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"SUBSCRIBE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"payload"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"appId"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"test_app_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"workspaceId"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"test_workspace_id"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me explain &lt;a href="https://redis.io/docs/manual/pubsub/" rel="noopener noreferrer"&gt;Redis pub/sub&lt;/a&gt;  which I am using as one of the solution for aforementioned problem.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Brief description on &lt;a href="https://redis.io/docs/manual/pubsub/" rel="noopener noreferrer"&gt;Redis Pub/Sub&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;First of all let’s understand &lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt;. It is an  in-memory data structure store which is used as a database, cache, message broker, and streaming engine. Redis pub/sub is one the features of Redis. You can get official documentation of Redis pub/sub &lt;a href="https://redis.io/docs/manual/pubsub/" rel="noopener noreferrer"&gt;here&lt;/a&gt; . Let me give you a brief on few of the concepts of Redis pub/sub. There are two components in Redis pub/sub first one is Publisher. Its function is to send message payload to a given channel/Topic. Subscribers, these subscribe/unsubscribe to a particular topic. A message sent to a topic by a publisher is received by all  subscribers subscribed to that topic. Given figure explains the principle of Redis pub/sub.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfes6w4tk8acydrk3dut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjfes6w4tk8acydrk3dut.png" alt="Redis pub/sub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Golang code snippet explaining subscription to a channel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;CacheStore&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;SubscribeSocketChannel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socketClient&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;redisPubsub&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RedisClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;storePubsubChannel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;redisPubsub&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Channel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Channel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;storePubsubChannel&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"received pubsub message:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;publishToSocketSubscribers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socketClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Golang code snippet explaining publishing to a channel&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;redisClient&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;workspaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;appId&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt;&lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;publishableData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;getPublishPayload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;workspaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;redisStore&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;NewCacheStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;redisClient&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;redisStore&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PublishToSocketChannel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;publishableData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that, you all have some idea of technologies I have used we can derive a viable solution to above mentioned problem. In simple words the problem is that all the server instance do not have the side effect / changes so they are unable to convey the changes/side effects to socket room subscribers. This can be easily solved by sending the changes from origin server to all the instances of the server.&lt;/p&gt;

&lt;p&gt;The Redis real time database store with pub/sub like functionality fits quite easily in this scenario to solve this problem. It can help us to publish the changed data across the server instances and then the subscribers at each server can receive the changes and then using socket this changes can be sent to all the subscribed collaborators/clients. Therefore using Redis pub/sub we can handle socket sessions across multiple instances of application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lvgwl3u2ph34h8k9inu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3lvgwl3u2ph34h8k9inu.png" alt="The solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have uploaded the Golang server code and Postman collection of apis and also the documentation on how to use the web socket using postman as a client on Github - &lt;a href="https://github.com/sonu0702/redis-socket-blog/tree/master" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post is in collaboration with Redis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn more:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://redis.info/3NBGJRT" rel="noopener noreferrer"&gt;Try Redis Cloud for free&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.info/3Ga9YII" rel="noopener noreferrer"&gt;Watch this video on the benefits of Redis Cloud over other Redis providers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.info/3LC4GqB" rel="noopener noreferrer"&gt;Redis Developer Hub - tools, guides, and tutorials about Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.info/3wMR7PR" rel="noopener noreferrer"&gt;RedisInsight Desktop GUI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>redis</category>
      <category>go</category>
      <category>socketio</category>
      <category>pubsub</category>
    </item>
    <item>
      <title>How to use Facial Recognition to Enhance user Experience ?</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Sun, 14 Aug 2022 09:57:00 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/how-to-use-facial-recognition-to-enhance-user-experience--5c5n</link>
      <guid>https://dev.to/sonu_sharma/how-to-use-facial-recognition-to-enhance-user-experience--5c5n</guid>
      <description>&lt;p&gt;Authentication technology is always changing. Businesses have to move beyond passwords and think of authentication as a means of enhancing user experience. Authentication methods like biometrics (facial authentication) eliminate the need to remember long and complex passwords. As a result of enhanced authentication methods and technologies, attackers will not be able to exploit passwords, and a data breach will be prevented.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is facial authentication ?
&lt;/h3&gt;

&lt;p&gt;It is an authentication system which authenticates and confirms identity of users instantly without Password, OTP codes, or security questions. &lt;/p&gt;

&lt;p&gt;These facial authentication systems are powered by  facial recognition engine which is the critical key component that is responsible for mapping each enrolled user’s face at real-time into a mathematical feature vector, better known as biometrics hash, which is in turn stored in a sand-boxed binary index.&lt;/p&gt;

&lt;p&gt;Two of the best examples of facial recognition engine are &lt;strong&gt;PixLab Insight&lt;/strong&gt; and &lt;strong&gt;AWS Rekognition&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://faceio.net/"&gt;FACEIO&lt;/a&gt; is a cross-browser, &lt;a href="https://faceio.net/pricing"&gt;Cloud&lt;/a&gt; &amp;amp; &lt;a href="https://faceio.net/on-premise"&gt;On-Premise&lt;/a&gt; deployable, facial authentication framework, It is powered by &lt;strong&gt;PixLab Insight&lt;/strong&gt; and &lt;strong&gt;AWS Rekognition&lt;/strong&gt; facial recognition engine*&lt;em&gt;,&lt;/em&gt;* with a client-side JavaScript library (fio.js) that &lt;a href="https://faceio.net/integration-guide"&gt;integrates seamlessly&lt;/a&gt; with any website or web application desiring to offer secure facial recognition experience to their users. You can freely test the accuracy of both engines by creating a new application on the &lt;a href="https://console.faceio.net/"&gt;FACEIO Console&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is expected from facial authentication ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Facial authentication must remove dependency of Email, Phone Number, Pin and other personal details of users specially on web application where personal notification are not required.&lt;/li&gt;
&lt;li&gt;Facial authentication  should be functional across devices like web browsers as well as mobile phone. &lt;a href="https://faceio.net/"&gt;FACEIO&lt;/a&gt; is one such facial authentication system. A PWA (Progressive Web Application) can be used to make it available to mobile phones. This reduces cost of using multiple facial authentication services.&lt;/li&gt;
&lt;li&gt;Should have Zero external dependency. Only standard technology implemented in plain JavaScript &amp;amp; CSS.&lt;/li&gt;
&lt;li&gt;Should have defence grade accuracy with faster  recognition speed powered by state-of-the-art facial recognition engines. &lt;a href="https://faceio.net/"&gt;FACEIO&lt;/a&gt; uses tried and tested &lt;strong&gt;PixLab Insight&lt;/strong&gt; and &lt;strong&gt;AWS Rekognition&lt;/strong&gt; facial recognition engines.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  History of facial authentication ?
&lt;/h3&gt;

&lt;p&gt;As we look forward to the future uses of Facial Recognition software, it’s good to take a step back and see how far we have come since the early beginnings.&lt;/p&gt;

&lt;p&gt;The earliest pioneers of facial recognition were Woody Bledsoe, Helen Chan Wolf and Charles Bisson. In 1964 and 1965, Bledsoe, along with Wolf and Bisson began work using computers to recognise the human face.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://faceio.net/"&gt;FACEIO Facial Recognition&lt;/a&gt; - Present&lt;br&gt;
&lt;a href="https://faceio.net/"&gt;FACEIO&lt;/a&gt; is a cross-browser, facial authentication framework that can be implemented on any website via simple JavaScript snippet &lt;strong&gt;to easily authenticate users via Face Recognition instead of the traditional login/password pair or OTP code.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;FACEIO is the easiest way to add passwordless authentication to web based applications. Simply &lt;a href="https://faceio.net/integration-guide"&gt;implement fio.js on your website&lt;/a&gt;, and you will be able to instantly authenticate your existing users, and enroll new ones via Face Recognition using their computer Webcam or smartphone frontal camera on their favorite browser.&lt;/p&gt;
&lt;h3&gt;
  
  
  Types of authentication systems ?
&lt;/h3&gt;

&lt;p&gt;Authentication technology is always changing. Businesses have to move beyond passwords and think of authentication as a means of enhancing user experience. Authentication methods like biometrics (facial authentication) eliminate the need to remember long and complex passwords. As a result of enhanced authentication methods and technologies, attackers will not be able to exploit passwords, and a data breach will be prevented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Password-based authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Passwords are the most common methods of authentication. Passwords can be in the form of a string of letters, numbers, or special characters. To protect yourself you need to create strong passwords that include a combination of all possible options.&lt;/p&gt;

&lt;p&gt;However, passwords are prone to phishing attacks and bad hygiene that weakens effectiveness. An average person has about 25 different online accounts, but only 54% of users use different passwords across their accounts.&lt;/p&gt;

&lt;p&gt;The truth is that there are a lot of passwords to remember. As a result, many people choose convenience over security. Most people use simple passwords instead of creating reliable passwords because they are easier to remember.&lt;/p&gt;

&lt;p&gt;The bottom line is that passwords have a lot of weaknesses and are not sufficient in protecting online information. Hackers can easily guess user credentials by running through all possible combinations until they find a match.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-factor authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Multi-Factor Authentication (MFA) is an authentication method that requires two or more independent ways to identify a user. Examples include codes generated from the user’s smartphone, Captcha tests, fingerprints, voice biometrics or facial recognition.&lt;/p&gt;

&lt;p&gt;MFA authentication methods and technologies increase the confidence of users by adding multiple layers of security. MFA may be a good defence against most account hacks, but it has its own pitfalls. People may lose their phones or SIM cards and not be able to generate an authentication code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Certificate-based authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Certificate-based authentication technologies identify users, machines or devices by using digital certificates. A digital certificate is an electronic document based on the idea of a driver’s license or a passport.&lt;/p&gt;

&lt;p&gt;The certificate contains the digital identity of a user including a public key, and the digital signature of a certification authority. Digital certificates prove the ownership of a public key and issued only by a certification authority.&lt;/p&gt;

&lt;p&gt;Users provide their digital certificates when they sign in to a server. The server verifies the credibility of the digital signature and the certificate authority. The server then uses cryptography to confirm that the user has a correct private key associated with the certificate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Biometric authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Biometrics authentication is a security process that relies on the unique biological characteristics of an individual. Here are key advantages of using biometric authentication technologies:&lt;/p&gt;

&lt;p&gt;Biological characteristics can be easily compared to authorized features saved in a database.&lt;br&gt;
Biometric authentication can control physical access when installed on gates and doors.&lt;br&gt;
You can add biometrics into your multi-factor authentication process.&lt;br&gt;
Biometric authentication technologies are used by consumers, governments and private corporations including airports, military bases, and national borders. The technology is increasingly adopted due to the ability to achieve a high level of security without creating friction for the user. Common biometric authentication methods include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Facial recognition&lt;/strong&gt;—matches the different face characteristics of an individual trying to gain access to an approved face stored in a database. Face recognition can be inconsistent when comparing faces at different angles or comparing people who look similar, like close relatives. Facial liveness like ID R&amp;amp;D’s passive facial liveness prevents spoofing.&lt;br&gt;
&lt;strong&gt;Fingerprint scanners&lt;/strong&gt;—match the unique patterns on an individual’s fingerprints. Some new versions of fingerprint scanners can even assess the vascular patterns in people’s fingers. Fingerprint scanners are currently the most popular biometric technology for everyday consumers, despite their frequent inaccuracies. This popularity can be attributed to iPhones.&lt;br&gt;
&lt;strong&gt;Speaker Recognition&lt;/strong&gt; —also known as voice biometrics, examines a speaker’s speech patterns for the formation of specific shapes and sound qualities. A voice-protected device usually relies on standardized words to identify users, just like a password.&lt;br&gt;
&lt;strong&gt;Eye scanners&lt;/strong&gt;—include technologies like iris recognition and retina scanners. Iris scanners project a bright light towards the eye and search for unique patterns in the colored ring around the pupil of the eye. The patterns are then compared to approved information stored in a database. Eye-based authentication may suffer inaccuracies if a person wears glasses or contact lenses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Token-based authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Token-based authentication technologies enable users to enter their credentials once and receive a unique encrypted string of random characters in exchange. You can then use the token to access protected systems instead of entering your credentials all over again. The digital token proves that you already have access permission. Use cases of token-based authentication include RESTful APIs that are used by multiple frameworks and clients.&lt;/p&gt;
&lt;h3&gt;
  
  
  Integrating facial Authentication in ReactJS project
&lt;/h3&gt;

&lt;p&gt;It is very easy to integrate facial authentication provided by FACEIO in ReactJS project. We have to import &lt;code&gt;fio.js&lt;/code&gt; on our site, initialize the library with our application Public ID, and finally perform  facial authentication operation. The official integrating guides, with accompanying code samples are available to consult at &lt;a href="https://faceio.net/integration-guide"&gt;faceio.net/integration-guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me walk you through the steps i have used to integrate &lt;code&gt;fio.js&lt;/code&gt; in my reactJS project. First and foremost i have used &lt;code&gt;codesandbox&lt;/code&gt; to make a demo app for facial authentication. &lt;code&gt;Codesandbox&lt;/code&gt; is my go to platform to create a demoable react apps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.faceio.net/fio.js"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have added this line of code in &lt;code&gt;public/index.html&lt;/code&gt; file as shown here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M8pZOSHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/640hjhunii2kz0l9dlsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M8pZOSHA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/640hjhunii2kz0l9dlsb.png" alt="integration" width="880" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the CDN for &lt;code&gt;fio.js&lt;/code&gt; is added we will be able to use this library in our ReactJS project. Let’s initialise the &lt;code&gt;faceio&lt;/code&gt; object in our &lt;code&gt;app.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;faceio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;faceIO&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="na"&gt;faceio&lt;/span&gt; &lt;span class="na"&gt;application&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&amp;gt;);
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;faceio&lt;/code&gt; variable is declared in globle scope within app.js. Once the component loads faceio variable will be initialised and will be available to use. &lt;code&gt;&amp;lt;&amp;lt;faceio application id&amp;gt;&amp;gt;&lt;/code&gt; is required to initialise the application. You can obtain the application id by following the steps in &lt;a href="https://faceio.net/integration-guide"&gt;https://faceio.net/integration-guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start the Facial Recognition process, we have to simply call &lt;code&gt;enroll()&lt;/code&gt; or &lt;code&gt;authenticate()&lt;/code&gt;, the only two exported methods of the &lt;code&gt;faceIO()&lt;/code&gt; class we instantiated earlier. &lt;code&gt;enroll()&lt;/code&gt; is for on-boarding new users (enrollment) while &lt;code&gt;authenticate()&lt;/code&gt; is for authenticating previously enrolled users (Identification/Sign-in).&lt;/p&gt;

&lt;p&gt;i have created two functions which implements &lt;code&gt;enroll()&lt;/code&gt; and &lt;code&gt;authenticate()&lt;/code&gt; functions respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleNewUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;faceio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;enroll&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;whoami&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1234543234&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;the response&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` Unique Facial ID: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;facialId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
      Enrollment Date: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
      Gender: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
      Age Approximation: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is done&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function handles the new user onboarding, which get triggered as the result of &lt;code&gt;onClick&lt;/code&gt; event of following button in my app component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mybutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleNewUser&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Sign-in (Enroll)
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On successful enrollment / onboarding of the user, &lt;code&gt;enroll()&lt;/code&gt; function returns the following payload&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;facialId&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0da974142bd048c2b0cb7e72aa83fb03fioa****"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;details&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="err"&gt;age&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="err"&gt;gender&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"male"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;timestamp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2022-08-14T04:18:38"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;facialId&lt;/code&gt; can be stored to recognise the users when they login.&lt;/p&gt;

&lt;p&gt;In order for the user to login into our application we will implement &lt;code&gt;authenticate()&lt;/code&gt; function given by &lt;code&gt;faceio&lt;/code&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleAuthentication&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;faceio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;auto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` Unique Facial ID: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;facialId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
          PayLoad: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;
          `&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function handles the user login, which get triggered as the result of &lt;code&gt;onClick&lt;/code&gt; event of following button in my app component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mybutton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleAuthentication&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Log-in
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we were building this whole application using &lt;code&gt;codesandbox&lt;/code&gt;  we do not have to deploy any where we can just start using it. &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/facial-authentication-re3hx0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Simply put as a developer we had four simple steps to get facial authentication using FACIO up and running for our users&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a new FACEIO application first: I Followed the &lt;strong&gt;Application Wizard&lt;/strong&gt; on the &lt;a href="https://console.faceio.net/"&gt;FACEIO Console&lt;/a&gt; to create the application it is pretty simple.&lt;/li&gt;
&lt;li&gt;It involved inputting an application name, &lt;strong&gt;selecting a facial recognition engine&lt;/strong&gt;
, cloud storage region, reviewing security options, customizing the Widget layout, and so forth...&lt;/li&gt;
&lt;li&gt;Then implemented &lt;code&gt;fio.js&lt;/code&gt;, the facial recognition JavaScript library on the website, and &lt;a href="https://faceio.net/integration-guide#fiojs-instantiate"&gt;initialised&lt;/a&gt; it with my  application Public ID.&lt;/li&gt;
&lt;li&gt;Tested it out once, to know everything working fine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are missing backend support for the facial authentication in this article. Will update this article as soon as i create a system design for the backend facial authentication and a demo able code to test my design.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>authentication</category>
      <category>facialrecongnitio</category>
      <category>facialauthenticatio</category>
    </item>
    <item>
      <title>useCallback the Hook</title>
      <dc:creator>sonu sharma</dc:creator>
      <pubDate>Sat, 06 Aug 2022 12:23:00 +0000</pubDate>
      <link>https://dev.to/sonu_sharma/usecallback-the-hook-5b3b</link>
      <guid>https://dev.to/sonu_sharma/usecallback-the-hook-5b3b</guid>
      <description>&lt;h2&gt;
  
  
  My 2 cents on useCallback React hook.
&lt;/h2&gt;

&lt;p&gt;useCallback hook memoizes the callback function passed to it as argument. In simple words it will not create another instance of same function until the value in second argument passed in  the useCallback as array of dependency changes.&lt;/p&gt;

&lt;p&gt;Simple way to test whether the passed callback function has changed is by the &lt;code&gt;set&lt;/code&gt; test. When ever the useCallback hook is called, add the function returned to the set and check the size of the set. if the size has increased that means a new function instance has been created.&lt;/p&gt;

&lt;p&gt;When you call useCallback hook with only one argument, that is without dependencies it does nothing. &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/usecallback-2dmys7?view=editor"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I think i have got the basics right. But i am not able to solve un necessary re-rendering of &lt;code&gt;&amp;lt;ShowProducts/&amp;gt;&lt;/code&gt; component. &lt;/p&gt;

&lt;p&gt;First of all  why it is a issue, it is a problem since i think &lt;code&gt;ShowProducts&lt;/code&gt; re-rendering is unnecessary because looking at the props i am passing to this components are &lt;code&gt;arrayOfProducts&lt;/code&gt; and a call back function to update how many times a item has been clicked / selected &lt;code&gt;updateSelectedCount&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I understand that every time &lt;code&gt;selectedCount&lt;/code&gt; changes a new instance of updateSelectedCount is generated so the ShowProducts component re-renders. But my question is why it should bother about the &lt;code&gt;updateSelectedCount&lt;/code&gt; being changed.&lt;/p&gt;

&lt;p&gt;My question is how i can stop re-rendering &lt;code&gt;&amp;lt;ShowProducts/&amp;gt;&lt;/code&gt; keeping all the functionality intact.&lt;/p&gt;

</description>
      <category>reactj</category>
      <category>javascript</category>
      <category>usecallback</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
