How do you render one million checkboxes in a browser and keep them synced in realtime? Well, using a combination of virtual scroll rendering, Redis bitmaps and bi-directional WebSocket communication. Let’s cover each of these concepts to build up this fun project — you’ll be surprised at how useful these techniques are for your own applications.
Let’s skip the database and build the ability to like any model in Laravel, using Redis. Traditionally you’d reach for the database for this kind of thing, but as you load more models and start performing checks within relationships — things begin to slow down. With a key-value store like Redis, tracking users who have liked comments (or anything) keeps everything ridiculously fast.
If you need to log unique views in Laravel, you might reach for a database table to track IP addresses or another unique piece of data. Let's take a look at speeding things up both in performance and complexity by using Redis and the HyperLogLog probabilistic data structure. Once we're done, we'll set up a period command to sync views back to the database for easy ordering, and then create a trait to share functionality between other models.