<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Scalegrid.io on Medium]]></title>
        <description><![CDATA[Stories by Scalegrid.io on Medium]]></description>
        <link>https://medium.com/@scalegridio?source=rss-75cb4bf85e95------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rlJNqNUrUC4YKYlj.png</url>
            <title>Stories by Scalegrid.io on Medium</title>
            <link>https://medium.com/@scalegridio?source=rss-75cb4bf85e95------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:02:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@scalegridio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How To Choose The Best MongoDB Hosting For Your Business]]></title>
            <link>https://medium.com/@scalegridio/how-to-choose-the-best-mongodb-hosting-for-your-business-a09f8e139bed?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/a09f8e139bed</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Thu, 04 Oct 2018 19:28:54 GMT</pubDate>
            <atom:updated>2018-10-04T19:28:54.584Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jj3wItnrED_L0nptkIq9Ig.jpeg" /></figure><p>So you’re planning a MongoDB database for your business (or you already have one) and you’re hunting for hosting. What are you looking for, exactly? How will you know when you’ve found the right host? Choose poorly and you’ll sabotage your future efforts in a big way, but choose smartly and you’ll have a supportive partner to help you grow.</p><p>Well, have no fear — in this piece, we’re going to review what makes MongoDB different, explain what makes hosting so important, cover the specific <a href="https://scalegrid.io/mongodb/products.html">MongoDB hosting</a> elements you need to investigate, and give you a clear indication of how to proceed. Let’s get started — <a href="https://scalegrid.io/blog/how-to-choose-the-best-mongodb-hosting-for-your-business/">how to choose the best MongoDB hosting for your business</a>.</p><h3>What makes MongoDB different?</h3><p>There are many different viable approaches to data storage and management in the business world, but the most common option for holding and sorting data is some form of relational database. A relational database links fields together by primary and secondary keys, avoiding redundancies and maintaining a rigid structure — something that works well in many cases, but certainly not all of them.</p><p>MongoDB, however, is a <a href="https://www.mongodb.com/scale/what-is-a-non-relational-database">non-relational database</a>. Through storing data in flexible files associated with objects (instead of tables or fields), it’s massively stronger for scalability and adaptability, which makes it perfect for businesses that require customizable data handling (as opposed to the passive rigid backup of a relational database). It also allows for easier data segmentation, where a whole series of relational database tables can often unravel following the deletion of just one field.</p><h3>Why is hosting so important for a MongoDB database?</h3><p>Since interactions with relational databases are typically fairly basic, minimal operational demands are placed on the hosts. Not so with something like MongoDB. Particularly if you’re storing data for a live application (or just software in development), you need a hosting service that can help you take maximum advantage of the available options.</p><p>If you make a poor choice in your quest for MongoDB hosting, you’ll have to make do with minimal feature accessibility at best — and if the host in question doesn’t really understand how to best handle a non-relational database, they could significantly <a href="https://2wtech.com/difference-between-data-security-and-data-integrity/">compromise the integrity and security of your data</a> through sheer ignorance.</p><p>If you choose well, you’ll have a supportive partner ready to guide you through the process of building, maintaining and expanding your MongoDB database. Given the innate flexibility of MongoDB, you’ll likely want to pursue that kind of expansion as your business matures.</p><h3>What to look for in a MongoDB host</h3><p>The most important thing to look for in a MongoDB host is a specific focus on MongoDB in particular. You may come across hosting providers who profess to support any platform you care to mention, and plenty such providers can follow through, but not <em>optimally</em>. If you have a high-end car in need of repairs, you don’t go to a generic mechanic — you go to an expert in that brand and benefit from their niche understanding.</p><p>Beyond that, you should concentrate on answering the following questions:</p><ul><li><strong>How good is the performance?</strong><br>When thinking about performance, look very carefully at <em>consistency</em>, because that’s ultimately what matters. Speed you can’t rely on to be there when you need it is of relatively little value. Seek assurances about <a href="https://www.lifewire.com/uptime-in-web-hosting-3467355">factors such as uptime</a> and upload/download rates.</li><li><strong>What kind of support is on offer?<br></strong>Unless you wrote the book on MongoDB, there are going to be gaps in your knowledge, and then there’s the prospect of someone else in your company needing assistance with database work. When there’s a MongoDB question to be answered, or there’s an issue with the hosting that needs to be resolved, there needs to be a solid support system in place to rapidly address your query.</li><li><strong>What are the backup options?</strong><br>Every hosting company has a different backup procedure with unique financial and organizational demands, and some companies charge extra for each backup or won’t allow custom scheduling. You can always backup data manually (quite easy when you pull data out to sync it with <a href="https://shopify.com/online-store">an exclusively-hosted ecommerce system</a> through a tool like <a href="https://zapier.com/apps/mongodb/integrations/shopify">Zapier</a> or <a href="https://www.stitchdata.com/integrations/shopify/mongodb/">Stitch</a>), but you shouldn’t have to.</li><li><strong>How is access handled?</strong><br>Security is always a major concern for any important database, and while a MongoDB database is inherently less susceptible to cascading alterations, it will also allow more in-depth tweaking. Your hosting company needs to be able to maintain excellent security levels.</li><li><strong>What are the reporting features?</strong><br>There’s a good chance that you’ll want to keep a close eye on the structure and activity of your MongoDB database over time, because it’s tough to make improvements if you don’t know which elements are working smoothly and which are causing issues. The provision of comprehensive reports from the host can save you a lot of time.</li></ul><p>Depending on the scale you’re aiming to work at, you may also want to confirm that you can communicate effectively with the hosting company on a personal level. Sometimes a hosting company can seem good on paper, but prove very awkward in practice as a result of a lack of professionalism and/or communication skills.</p><h3>The advantages of ScaleGrid</h3><p>Given the context, you’d of course expect me to bring up ScaleGrid, and of course I’m doing just that — but I won’t give you an extended marketing spiel, because the information is all there for you to review at your leisure. Take a look at <a href="https://scalegrid.io/mongodb/hosting-comparison.html">this comparison between ScaleGrid and other MongoDB hosting providers</a> and draw your own conclusions about what’s best for you.</p><p>I will, however, highlight a couple of notable things you should consider:</p><ul><li><strong>ScaleGrid offers unrivaled customization.</strong><br>Taking a fundamentally modular approach to database hosting, ScaleGrid provides outstanding plug-and-play functionality — through the ScaleGrid console, you can manage multiple databases connected to the cloud storage solutions of your choice.</li><li><strong>You can host MongoDB in your own cloud account.</strong><br>Unlike all other Database-as-a-Service (DBaaS) providers, ScaleGrid allows you to manage your hosted MongoDB clusters in your own <a href="https://scalegrid.io/mongodb/aws.html">AWS</a> or <a href="https://scalegrid.io/mongodb/azure.html">Azure</a> cloud account. Why is this important? Because it allows you to leverage Reserved Instances to save up to 80% on your long-term hosting costs, and access advanced security capabilities like Virtual Private Clouds and Security Groups for next-level access control.</li><li><strong>You’re able to keep full control over your MongoDB clusters.</strong><br>One of the most important considerations when choosing a MongoDB hosting provider is the level of control you’re able to retain over your clusters. ScaleGrid is, again, the only DBaaS that lets you keep full MongoDB admin access, along with full SSH root access to your machines.</li><li><strong>You’ve every reason to give ScaleGrid a try.</strong><br>Not only is there a great financial incentive to <a href="https://scalegrid.io/pricing/offers/switching-providers.html">switch to ScaleGrid from another MongoDB host</a> if you have one, but there’s also a 30-day trial if you’re just starting out with MongoDB and want to sample a solution without committing.</li></ul><p>If you find that another hosting solution is better for your particular needs, then by all means go for it. ScaleGrid likely isn’t going to be the right choice for <em>every </em>situation, after all. Just make sure that you take your time to consider the best way to proceed, and do plenty of research.</p><h3>Making a smart decision</h3><p>For all the reasons we’ve covered, hosting is very important in general, and <em>incredibly </em>important for supporting a MongoDB database. It’s not a decision to take lightly. You might feel that you’ll save time and effort by simply going for the first hosting solution you see, but that short-term saving would likely cost you dearly in the future. You’re making an investment in your business prospects — the time you put into choosing the best host today will pay off hugely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/0*Y3CtN1v05uR5_Xyj" /></figure><p><a href="https://microstartups.org/">Kayleigh Alexandra</a> is the startup-obsessed content writer for Micro Startups, a site with an unrelenting focus on extolling the virtues of the entrepreneurial spirit. Head to the MS blog for the latest news in the world of small business, and be sure to follow us on Twitter <a href="https://twitter.com/getmicrostarted">@getmicrostarted</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a09f8e139bed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain: What Is It, How It Works, And What It Means For Big Data]]></title>
            <link>https://medium.com/@scalegridio/blockchain-what-is-it-how-it-works-and-what-it-means-for-big-data-b68365638fdf?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/b68365638fdf</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[digital-transformation]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 15:15:35 GMT</pubDate>
            <atom:updated>2018-09-26T15:15:35.794Z</atom:updated>
            <content:encoded><![CDATA[<h3>In this new <a href="https://scalegrid.io/blog/digital-transformation-it-all-starts-with-data-thinking/">digital transformation</a> era, blockchain comes hand-in-hand as one of the fastest growing technologies to help secure and protect data through cryptography.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2Zh5_KmiSvD73-K9bGyig.jpeg" /><figcaption>ScaleGrid Blog</figcaption></figure><h3>What is Blockchain?</h3><p>Blockchain is a secure, shared, decentralized, distributed, immutable database that maintains a continuously growing list of records called blocks. <a href="https://www.researchgate.net/publication/315858662_Blockchain_Technology_as_an_Enabler_of_Service_Systems_A_Structured_Literature_Review">Seebacher &amp; Schüritz</a> further describes the distributed database as a “shared among and agreed upon a peer-to-peer network. It consists of a linked sequence of blocks (a storage unit of transaction), holding timestamped transactions that are secured by public-key cryptography (i.e., “hash”) and verified by the network community. Once an element is appended to the blockchain, it cannot be altered, turning a blockchain into an immutable record of past activity.” Learn more about <a href="https://scalegrid.io/blog/blockchain-what-is-it-how-it-works-and-what-it-means-for-big-data/">what blockchain means for big data</a>.</p><h3>How Does Blockchain Work?</h3><p>At the core of the blockchain technology is a distributed ledger with groups of transactions collected into a block. The block is validated by a third party (miner) and is locked. Each participant in the global network keeps a copy of the ledger and every time a new block is created, it is broadcasted to all the participants that add it to their local copy of the ledger. The process of “hashing” transforms assets which are encoded “tokens” and can be registered, tracked, and traded with a private key on a given blockchain. Transactions are validated in real-time, and contracts are created when the value is transferred and certain pre-configured business rules or algorithms are met. These are called <a href="https://blockgeeks.com/guides/smart-contracts/">Smart Contracts</a>, and believed to one day replace the need for lawyers in the future.</p><p><a href="https://hbr.org/2017/01/the-truth-about-blockchain">Harvard Business Review</a> compares Blockchain as one of the foundational technologies, akin to the computer networking technology (TCP/IP) of the 1970’s that laid the groundwork for the development of the internet. The most widely recognized use case, cryptocurrencies, was led by Bitcoin as the first application which used Blockchain for digital currency. Today, Blockchain as a distributed ledger technology, along with existing technologies like the Internet of Things (IoT), Global Positioning Systems (GPS), etc. is set to revolutionize industries across the board, including financial institutions, healthcare, manufacturing, retail, consumer goods, oil and gas, and hospitality to name just a few. Any market, sector, or application that needs to securely exchange data in a decentralized format has a great argument for adopting Blockchain for their big data initiatives.</p><h3>What Blockchain Means for Big Data</h3><p>Blockchain’s storage of secure, trustless, authenticated, replicated, non-erasable sets of data (blocks) is a call-out to the world of Big Data. The ever-increasing store of transactional mining data in these distributed ledgers will overwhelm the current world capacity of data lakes. While Blockchain applications and use cases are still in its nascent stages, the potential for digital transformation is immense. As more real-world Blockchain applications are rolled out, Big Data is just going to get bigger.</p><p>According to <a href="https://www.idc.com/getdoc.jsp?containerId=prUS41826116">IDC</a>, worldwide revenues for big data and business analytics will grow from $130.1 billion in 2016 to more than $203 billion in 2020, at a compound annual growth rate (CAGR) of 11.7%. <a href="https://www.cloudcomputing-news.net/news/2018/jul/27/blockchain-spending-will-double-in-2018-to-reach-15b/">IDC</a> further expects blockchain spending to grow rapidly throughout the 2017–2022 forecast period, with a five-year compound annual growth rate (CAGR) of 73.2 percent. Moreover, worldwide blockchain spending will reach $1.5 billion in 2018 — that’s double the amount spent on the emerging technology during 2017. Welcome to the next gold rush, the wild west of Big Data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b68365638fdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Caching Tweets Using Node.js, Redis and Socket.io]]></title>
            <link>https://medium.com/@scalegridio/caching-tweets-using-node-js-redis-and-socket-io-a4aff0aa58f2?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4aff0aa58f2</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Mon, 28 Aug 2017 03:29:53 GMT</pubDate>
            <atom:updated>2017-08-28T03:29:53.432Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://scalegrid.io/">ScaleGrid</a> is the only <a href="https://scalegrid.io/mongodb/products.html">MongoDB</a> and <a href="https://scalegrid.io/redis/products.html">Redis</a> hosting solution that lets you manage mongo instances on both public &amp; private clouds and on premise from a single central console. Recently launched -<a href="https://scalegrid.io/mongodb/azure.html">MongoDB azure</a>. Try us free for 30 days.</h4><p><em>In this recent article we published on our </em><a href="https://scalegrid.io/blog/caching-tweets-using-node-js-redis-and-socket-io-2/"><em>ScaleGrid blog</em></a><em>, we discuss building a streaming list of tweets based on a search query entered by the user. The tweets will be fetched using Twitter’s Streaming API, stored in a Redis list and updated in the front-end using Socket.io. We will primarily be using Redis as a caching layer for fetching tweets.</em></p><h3>Introduction</h3><p>Here is a brief description of the technologies we will be using:</p><h3>Redis</h3><p>Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes with radius queries.</p><h3>Node.js</h3><p>Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, and thus perfect for data-intensive real-time applications that run across distributed devices.</p><h3>Express.js</h3><p>Express.js is a Node.js framework. You can create the server and server-side code for an application like most of the other web languages but using JavaScript.</p><h3>Socket.IO</h3><p>Socket.IO is a JavaScript library for real-time web applications. It enables real-time, bi-directional communication between web clients and servers. It has two parts: a client-side library that runs on the browser, and a server-side library for Node.js. Both the components have nearly identical APIs.</p><h3>Heroku</h3><p>Heroku is a cloud platform that lets companies build, deliver, monitor, and scale apps — it is the fastest way to go from idea to URL, bypassing all those infrastructure headaches.</p><p>This article assumes that you already have Redis, Node.js, and the Heroku Toolbelt installed on your machine.</p><h3>Setup</h3><p>- Download the code from the following repository: <a href="https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-twitter-search/node-socket-redis-twitter-hashtags">https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-twitter-search/node-socket-redis-twitter-hashtags</a></p><p>- Run npm install to install the necessary components</p><p>- Finally, you can start the node server by doing “node index.js”. You can also run “nodemon” which watches for file changes as well.</p><p>You can also access a hosted version of this app here: <a href="https://node-socket-redis-stream-tweet.herokuapp.com/">https://node-socket-redis-stream-tweet.herokuapp.com/</a></p><h3>The Process</h3><p>Here is a brief description of the process that we will be using to build the demo application:</p><p>1. We will start by accepting a search query from the user. The query can be Twitter mentions, hashtags or any random search text.</p><p>2. Once we have the search query, we will send it to Twitter’s Streaming API to fetch tweets. Since it is a stream, we will be listening when tweets are sent by the API.</p><p>3. As soon as a tweet is retrieved, we will store it in a Redis list and broadcast it to the front-end.</p><h3>What are Redis lists?</h3><p>Redis lists are implemented via Linked Lists. This means that even if you have millions of elements inside a list, the operation of adding a new element at the head or at the tail of the list is performed in constant time. The speed of adding a new element with the LPUSH command to the head of a list with ten elements is the same as adding an element to the head of list with 10 million elements.</p><p>In our application, we will be storing the tweets received via the API in a list called “tweets”. We will use LPUSH to push the newly received tweet to the list, trim it using LTRIM which restricts the amount of disk space used (as writing a stream may take a lot of space), fetch the latest tweet using LRANGE, and broadcast it to the front-end where it will be appended to the streaming list.</p><h3>What is LPUSH, LTRIM and LRANGE?</h3><p>These are a set of Redis commands that are used to add data to a list. Here is a brief description:</p><h3>LPUSH</h3><p>Insert all the specified values at the head of the list stored at key. If key does not exist, it is created as an empty list before performing the push operations. When key holds a value that is not a list, an error is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqeQdWbg33fBrgIL3N5VOQ.png" /></figure><h3>LTRIM</h3><p>Trim an existing list so that it will contain only the range of elements specified. Both start and stop are zero-based indexes, where 0 is the first element of the list (the head), 1 the next one element and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdD4SXWsTVw0_kVq9lzPnw.png" /></figure><h3>LRANGE</h3><p>Returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next, and so on.</p><p>These offsets can also be negative numbers indicating positions from the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GcqculhGEdFvnH0ciGqKQ.png" /></figure><h3>Building the application</h3><p>Our demo requires both a front-end and a back-end. Our front-end is a pretty simple text box with a button that will be used to start the stream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01gejctYsReW207FMv5JQQ.png" /></figure><p>We need a helper function to build a tweet box once we receive the tweet from our back-end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eo9FmhAqu6f5zELu158ZIQ.png" /></figure><p>We also need a listener to stop the stream and prevent adding any more tweets to the streaming list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtDe9LeEyEBqy4wMh12tsA.png" /></figure><p>Let’s switch over to the back-end side of things and start writing our /search API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SW_cp4N3einmLuIYxeo_oQ.png" /></figure><p>The above code contains the core of our back-end. Once a request has been received at /search, we start the stream using Twitter’s streaming API that returns a stream object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VhWOeFUZ91DHloc7tRGJWw.png" /></figure><p>We can listen to the stream object for a key called “data” that will send us a new tweet when available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FId9wVcNQ7z-XCgndy1XRA.png" /></figure><p>The “data” object contains the tweet JSON which may look something like this (part of the response has been omitted):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBZEF8lziHhUCSf81E_zXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*joL2XnMHbA6oSkvnrwsUtQ.png" /></figure><p>We store this response in a Redis list called “tweets” using LPUSH:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsIOfv3RcATyzuB5_sTRdw.png" /></figure><p>Once the tweet has been saved, we trim the list using LTRIM to keep a max number of tweets (so our disk space doesn’t get full):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JNSDRSVbWKO626BoorUSDQ.png" /></figure><p>After trimming the list, we fetch the latest tweet using LRANGE and emit it to the front-end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NMxOh8F_o0hLyyPviwxvuA.png" /></figure><p>Since this is a demo application, we also need to manually destroy the stream after a specific time so it doesn’t keep writing to disk:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WuMqVfZWZFC5lknImVeRoQ.png" /></figure><p>And you’re done! Fire up the server using npm start and enjoy the streaming experience.</p><p>A demo of the application is available here: <a href="https://node-socket-redis-stream-tweet.herokuapp.com/">https://node-socket-redis-stream-tweet.herokuapp.com/</a></p><p>For deploying this application on Heroku, check out their docs: <a href="https://devcenter.heroku.com/categories/deployment">https://devcenter.heroku.com/categories/deployment</a></p><p>The entire source code is also available on GitHub for you to fork and work on: <a href="https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-twitter-search/node-socket-redis-twitter-hashtags">https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-twitter-search/node-socket-redis-twitter-hashtags</a></p><p>As always, if you build something awesome, do tweet us about it <a href="https://twitter.com/scalegridio">@scalegridio</a></p><p>If you need help with <a href="https://scalegrid.io/redis/products.html">Redis hosting</a> and management, reach out to us at support@scalegrid.io for further information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4aff0aa58f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding & Managing Disk Space On Your MongoDB Server]]></title>
            <link>https://medium.com/@scalegridio/understanding-managing-disk-space-on-your-mongodb-server-d8f3ff359131?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8f3ff359131</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[storage-solutions]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Tue, 18 Jul 2017 00:49:35 GMT</pubDate>
            <atom:updated>2017-07-18T00:49:35.929Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://scalegrid.io/">ScaleGrid</a> is the only <a href="https://scalegrid.io/mongodb/products.html">MongoDB</a> and <a href="https://scalegrid.io/redis/products.html">Redis</a> hosting solution that lets you manage mongo instances on both public &amp; private clouds and on premise from a single central console. Recently launched -<a href="https://scalegrid.io/mongodb/azure.html">MongoDB azure</a>. Try us free for 30 days.</h4><p><em>This post was recently published on the </em><a href="https://scalegrid.io/blog/understanding-managing-disk-space-on-your-mongodb-server/"><em>ScaleGrid blog</em></a><em> and helps you understand and manage disk space on your MongoDB server. Our tips are essential so you can understand and be aware of MongoDB storage statistics and how you can compact or repair the database to handle fragmentation.</em></p><p>Disk storage is a critical resource for any scalable database system. The performance of disk-based databases is dependent on how data is managed on the disk. Your <a href="https://www.mongodb.com/">MongoDB</a> server supports various pluggable <a href="https://docs.mongodb.com/manual/core/storage-engines/">storage engines</a> that handle the storage management. MongoDB storage engines initially store all documents sequentially. As the database grows, and multiple write operations run, this contiguous space gets fragmented into smaller blocks with chunks of free space in between. The usual solution is to increase the disk size in such situations; however, there are alternatives that can help you regain the free space without scaling the disk size.</p><h3>How Large is Your Database Really?</h3><p>You should always keep an eye on the amount of free disk space on your production server. It would also be prudent to know your database size when you are paying for it on a cloud platform. MongoDB has a command <a href="https://docs.mongodb.com/manual/reference/method/db.stats/">db.stats()</a><strong> </strong>that can provide insights into the storage statistics of a MongoDB instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x41wZ5itB39JxQeeKRAdlQ.png" /></figure><p><strong>dataSize:</strong> The total size in bytes of the <strong>uncompressed data</strong> held in this database.</p><p><strong>storageSize: </strong>The total amount of <strong>disk space</strong> allocated to all collections in the database.</p><p>The response of <a href="https://docs.mongodb.com/manual/reference/method/db.stats/">db.stats()</a><strong> </strong>is dependent on the type of MongoDB engine. You can find version-dependent description of above metrics at <a href="https://docs.mongodb.com/manual/reference/method/db.stats/">MongoDB documentation</a>.</p><p>Why the big difference between <strong>storageSize</strong> and <strong>dataSize</strong>? This is due to fragmentation of data files that was explained earlier. MongoDB tries to reuse free space in between fragmented data whenever possible and does not release it to the operating system. However in WiredTiger, storageSize may be smaller than dataSize if <a href="https://scalegrid.io/blog/enabling-data-compression-in-mongodb-3-0/">compression is enabled</a>.</p><p>In case a large chunk of data is deleted from a collection and the collection never uses the deleted space for new documents, this space needs to be returned to the operating system so that it can be used by other databases or collections. You will need to run a <strong>compact </strong>or <strong>repair</strong> operation in order to defragment the disk space and regain the usable free space.</p><h3><a href="https://docs.mongodb.com/manual/reference/command/compact/">Compacting MongoDB</a></h3><p>MongoDB <a href="https://docs.mongodb.com/manual/reference/command/compact/">compact operation</a> rewrites all documents and indexes in a collection to contiguous blocks of disk space. However, this operation blocks all other operations on the database to which the collection belongs. So, for a standalone server, it is recommended to run it during a maintenance window. For replica sets, you should run it in a rolling fashion for each shard. This means compacting all secondaries first, and then finally the primary. Thus, database availability would be not be affected. The syntax of the command is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bSK0HSPruEwXBetmtTkHYg.png" /></figure><p><strong>1. </strong><a href="https://docs.mongodb.com/manual/core/mmapv1/"><strong>MMAPv1</strong></a></p><ul><li>Compaction operation defragments data files &amp; indexes. However, it does not release space to the operating system. The operation is still useful to defragment and create more contiguous space for reuse by MongoDB. However, it is of no use though when the free disk space is very low.</li><li>An additional <a href="https://docs.mongodb.com/manual/reference/command/compact/#mmapv1">disk space up to 2GB</a> is required during the compaction operation.</li><li>A database level lock is held during the compaction operation.</li></ul><p><strong>2. </strong><a href="https://docs.mongodb.com/manual/core/wiredtiger/"><strong>WiredTiger</strong></a></p><p>The WiredTiger engine provides <a href="https://www.mongodb.com/blog/post/new-compression-options-mongodb-30">compression</a> by default which consumes less disk space than MMAPv1.</p><ul><li>The compact process releases the free space to the operating system.</li><li><a href="https://docs.mongodb.com/manual/reference/command/compact/#wiredtiger">Minimal disk space</a> is required to run the compact operation.</li><li>WiredTiger also blocks all operations on the database as it needs database level lock.</li></ul><p>If you are running WiredTiger. We recommend you run the compact operation when the storage has reached 80% of the disk size. You can do this by triggering ‘Compact’ operation from our details page.</p><p><a href="https://docs.mongodb.com/manual/reference/command/repairDatabase/"><strong>Repair MongoDB</strong></a></p><p>MongoDB <strong>repair</strong> operation repairs all errors &amp; inconsistencies in data storage. It is similar to <a href="https://linux.die.net/man/8/fsck">fcsk</a>command for a file system. This command ensures the data integrity after unexpected shutdown or crashes. However, if journaling is enabled on server then there is no requirement of repair, server uses journal to get into clean state automatically after restart. In case, your database has been corrupted, then a <strong>repair database</strong> would not save the corrupt data. Therefore, it is not recommended to use this operation for <strong>data recovery</strong> when you have other options. For MMAPv1, <strong>repairDatabase</strong> is only way to reclaim disk space if you think that your database is not corrupted and have enough space required by repair operation. The syntax of the command is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUsviwYER-IT5t9v_SVv4g.png" /></figure><ul><li>This command compacts all collections in the database and recreates all indexes.</li><li>The job requires free disk space equal to the size of your <a href="https://docs.mongodb.com/manual/reference/command/repairDatabase/">current data set plus 2 gigabytes</a>.</li></ul><p>At ScaleGrid, we use the <strong>repairDatabase</strong> operation to reclaim free space for <strong>MMAPv1</strong> engine clusters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8f3ff359131" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing in-memory databases: Redis vs MongoDB (Percona Memory Engine)]]></title>
            <link>https://medium.com/@scalegridio/comparing-in-memory-databases-redis-vs-mongodb-percona-memory-engine-724863a4f8bb?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/724863a4f8bb</guid>
            <category><![CDATA[in-memory-computing]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Tue, 20 Jun 2017 17:03:43 GMT</pubDate>
            <atom:updated>2017-06-20T17:03:43.070Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://scalegrid.io/">ScaleGrid</a> is the only <a href="https://scalegrid.io/mongodb/products.html">MongoDB</a> and <a href="https://scalegrid.io/redis/products.html">Redis</a> hosting solution that lets you manage mongo instances on both public &amp; private clouds and on premise from a single central console. Recently launched -<a href="https://scalegrid.io/mongodb/azure.html">mongoDB azure</a>. Try us free for 30 days.</h4><p><em>This post was recently published on the ScaleGrid blog and compares </em>two of the<a href="https://db-engines.com/en/ranking"> most popular NoSQL databases</a>:<a href="https://redis.io/"> Redis</a> and<a href="https://www.mongodb.com/"> MongoDB</a> (in an altered form).</p><p>Redis is a popular in-memory data structure store that stores data as key-value pairs. It is primarily used as a very fast data structure store, a cache, or a message broker among other things. Being in-memory, it is the data store of choice when response times triumphs everything else.</p><p>MongoDB is an on-disk document store that provides a JSON interface to data and has a very rich query language. Known for it’s speed, efficiency and scalability, it is the most popular NoSQL database currently. However, being on-disk, MongoDB can’t compare favorably to an in-memory database like Redis in terms of absolute performance. But with the availability of the in-memory<a href="https://docs.mongodb.com/manual/core/storage-engines/"> storage engines</a> for MongoDB, a more direct comparison becomes feasible.</p><h3>Percona Memory Engine for MongoDB</h3><p><a href="https://www.mongodb.com/blog/post/mongodb-pluggable-storage-engines-state-of-the-union-storage-engine-summit">Starting with version 3.0, MongoDB provides an API</a> to plug in a<a href="https://docs.mongodb.com/manual/core/storage-engines/"> storage engine</a> of your choice. A storage engine, from the MongoDB context, is the component of the database that is responsible for managing how data is stored, both in-memory and on-disk. MongoDB supports an<a href="https://docs.mongodb.com/manual/core/inmemory/"> in-memory storage engine</a>; however, it’s currently limited to the Enterprise edition of the product. In 2016,<a href="https://www.percona.com/"> Percona</a> released an in-memory engine for MongoDB Community Edition called the<a href="https://www.percona.com/doc/percona-server-for-mongodb/3.2/inmemory.html#inmemory"> Percona Memory Engine for MongoDB</a> that is open source. Like MonogDB’s in-memory engine, it too is a variation of the<a href="https://docs.mongodb.com/manual/core/wiredtiger/"> WiredTiger</a> storage engine but with no persistence to disk.</p><h3>Advantages of Redis as a Cache</h3><p>With an in-memory MongoDB storage engine in place, we have a level playing field between Redis and MongoDB. However, what is still the need to compare the two? Let’s look at the advantages of each of them as caching solutions.</p><p>Let’s look at Redis first.</p><ul><li>A well-known caching solution that excels at it.</li><li>Redis isn’t a plain cache solution — it provides<a href="https://redis.io/topics/data-types-intro"> advanced data structures</a> that provide a lot of powerful ways to save and query data which can’t be achieved with a vanilla key-value cache.</li><li>Redis is fairly simple to setup, use and learn.</li><li>Redis provides persistence should you choose to set it up. So cache warming in case of crashes is hassle free.</li></ul><p>Some disadvantages for Redis are: it doesn’t have in-built encryption on wire,<a href="https://en.wikipedia.org/wiki/Role-based_access_control"> RBAC</a>, a seamless, mature clustering solution, and can be a pain to deploy of large-scale cloud deployments, etc.</p><h3>Advantages of MongoDB as a Cache</h3><ul><li>MongoDB is a more traditional database with advanced data manipulation features (think<a href="https://docs.mongodb.com/manual/aggregation/"> aggregations and map-reduce</a>) and a rich query language.</li><li>Has SSL, RBAC and scale-out built in.</li><li>If you are already using MongoDB as your primary database, then your operational and development costs drop as there would be just one database to learn and manage.</li></ul><p>Look at<a href="https://www.percona.com/blog/2016/08/11/introducing-percona-memory-engine-mongodb/"> this post</a> from Peter on where the MongoDB in-memory engine might be a good fit.</p><p>One significant disadvantage for MongoDB with an in-memory engine is that it offers no persistence until it is deployed as a replica set with persistence configured on the read replica(s).</p><p><strong>In this post, we will focus on quantifying the performance differences between Redis and MongoDB</strong>. Operational differences and qualitative comparison will be covered in subsequent posts.</p><h3>Redis vs In-Memory MongoDB : Performance</h3><h3>TL;DR</h3><ul><li><strong>Redis performs considerably better for reads</strong> for all sorts of workload and <strong>better for writes as the workloads increase.</strong></li><li>Even though MongoDB utilizes all the cores of the system, it gets CPU-bound comparatively early. While it had compute available, it was better at writes than Redis.</li><li>Both of the databases are eventually compute-bound. And even though Redis is single-threaded, it (mostly) gets more done with running on one core than MongoDB does while saturating all the cores.</li><li><strong>Redis</strong>, for non-trivial data sets,<a href="https://scalegrid.io/blog/?p=2318&amp;preview=true&amp;preview_id=2318&amp;preview_nonce=631946c5a0&amp;post_format=standard#appendixb"> <strong>uses a lot more RAM compared to MongoDB</strong></a> to store the same amount of data.</li></ul><h3>Configuration</h3><p>The tool we used to measure performance was<a href="https://github.com/brianfrankcooper/YCSB"> YCSB</a>. We have been using<a href="https://scalegrid.io/blog/how-to-benchmark-mongodb-with-ycsb/"> YCSB to compare and benchmark performance of MongoDB</a> on<a href="https://scalegrid.io/blog/comparing-mongodb-performance-on-public-clouds-aws-azure-digital-ocean/"> various cloud providers</a> and for<a href="https://scalegrid.io/blog/the-fastest-mongodb-on-azure/"> various configurations</a> in the past. We assume a basic understanding of<a href="https://github.com/brianfrankcooper/YCSB/wiki/Core-Workloads"> YCSB workloads</a> and<a href="https://github.com/brianfrankcooper/YCSB/wiki/Running-a-Workload"> features</a> in the test rig description.</p><ul><li><strong>Database instance type </strong><a href="https://aws.amazon.com/ec2/instance-types/">— AWS EC2</a> c4.xlarge featuring 4 cores, 7.5 GB memory and<a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html"> enhanced networking</a> to ensure we don’t have network bottlenecks.</li><li><strong>Client Machine </strong><a href="https://aws.amazon.com/ec2/instance-types/">— AWS EC2</a> c4.xlarge in the same VPC as the database servers.</li><li><strong>Redis</strong> — version 3.2.8 with AOF and RDB turned off. Standalone.</li><li><strong>MongoDB</strong> — Percona Memory Engine based on MongoDB version 3.2.12. Standalone.</li><li><strong>Network Throughput</strong>: Measured via<a href="https://iperf.fr/"> iperf</a> as<a href="https://aws.amazon.com/premiumsupport/knowledge-center/network-throughput-benchmark-linux-ec2/"> recommended by AWS</a>:</li><li>Test Complete. Summary Results:<br>[ ID] Interval Transfer Bandwidth Retr<br>[ 4] 0.00–60.00 sec 8.99 GBytes <strong>1.29 Gbits/sec</strong> 146 sender<br>[ 4] 0.00–60.00 sec 8.99 GBytes <strong>1.29 Gbits/sec </strong>receiver</li><li><strong>Workload Details </strong>-</li></ul><ol><li>Insert Workload: 100 % Write — 2.5 million records</li><li>Workload A: Update heavy workload — 50%/50% Reads/Writes — 25 million operations</li><li>Workload B: Read mostly workload — 95%/5% Reads/Writes — 25 million operations</li></ol><ul><li><strong>Client Load</strong> — Throughput and latency measured over incrementally increasing loads generated from the client by increasing the number of YCSB client load threads, starting at 8 and growing in multiples of 2.</li></ul><h3>Results</h3><h3>Workload B Performance</h3><p>Since the primary use case for in-memory databases is cache, let’s look at Workload B first.</p><p>Here are the throughput/latency numbers from the 25 million operations workload. The ration of reads:writes was 95:5. This would be a representative cache reading workload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMhdhwF5VOwb7WFVps5TVg.png" /></figure><p><em>Note: Throughput is plotted against the primary axis (left), while latency is plotted against the secondary axis (right).</em></p><p>Observations during the run:</p><ul><li>For MongoDB, CPU was saturated by 32 threads onwards. Greater than 300% usage with single digit idle %ages.</li><li>For Redis, CPU utilization never crossed 95%. <strong>So Redis was consistently doing considerably better than MongoDB while running on a single thread, while MongoDB was saturating all the cores of the machine.</strong></li><li>For Redis, at 128 threads, runs used to fail often with read timeout exceptions.</li></ul><h3>Workload A Performance</h3><p>Here are the throughput/latency numbers from the 25 million operations workload. The ration of reads:writes was 50:50.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfI6J2kxiX8gXdSbU7tCjg.png" /></figure><p>Observations during the run:</p><ul><li>For MongoDB, CPU was saturated by 32 threads onwards. Greater than 300% usage with single digit idle %ages.</li><li>For Redis, CPU utilization never crossed 95%.</li><li>For Redis, by 64 threads and above, runs failed often with read timeout exceptions.</li></ul><h3>Insert Workload Performance</h3><p>Finally, here are the throughput/latency numbers from the 2.5 million record insertion workload. The number of records was selected to ensure that total memory used in case of Redis did not exceed 80% (since Redis is a memory hog. See Appendix B below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CfPvKG6DcbfW-hUn5tm12w.png" /></figure><p>Observations during the run:</p><ul><li>For MongoDB, CPU was saturated by 32 threads onwards. Greater than 300% usage with single digit idle %ages.</li><li>For Redis, CPU utilization never crossed 95%.</li></ul><h3>Appendices</h3><h3>A: Single-Thread Performance</h3><p>I had a strong urge to find this out — even though it is not very useful in real world conditions: who would be better when applied the same load from a single thread. That is, the performance of a single threaded application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWs5VyXl_wFDZzQWch-1FQ.png" /></figure><h3>B: Database Size</h3><p>The<a href="https://github.com/brianfrankcooper/YCSB/wiki/Core-Properties#core-workload-package-properties"> default format of records</a> inserted by YCSB are: each record is of 10 fields and each field is of 100 bytes. Assuming each record to be around 1KB, the total expected size in memory would be upwards of 2.4 GB. There was a stark contrast in the actual sizes as seen on the databases.</p><h4>MongoDB</h4><p>&gt; db.usertable.count()<br>2500000<br>&gt; db.usertable.findOne()<br>{<br> “_id” : “user6284781860667377211”,<br> “field1” : BinData(0,”OUlxLllnPC0sJEovLTpyL18jNjk6ME8vKzF4Kzt2OUEzMSEwMkBvPytyODZ4Plk7KzRmK0FzOiYoNFU1O185KFB/IVF7LykmPkE9NF1pLDFoNih0KiIwJU89K0ElMSAgKCF+Lg==”),<br> “field0” : BinData(0,”ODlwIzg0Ll5vK1s7NUV1O0htOVRnMk53JEd3KiwuOFN7Mj5oJ1FpM11nJ1hjK0BvOExhK1Y/LjEiJDByM14zPDtgPlcpKVYzI1kvKEc5PyY6OFs9PUMpLEltNEI/OUgzIFcnNQ==”),<br> “field7” : BinData(0,”N155M1ZxPSh4O1B7IFUzJFNzNEB1OiAsM0J/NiMoIj9sP1Y1Kz9mKkJ/OiQsMSk2OCouKU1jOltrMj4iKEUzNCVqIV4lJC0qIFY3MUo9MFQrLUJrITdqOjJ6NVs9LVcjNExxIg==”),<br> “field6” : BinData(0,”Njw6JVQnMyVmOiZyPFxrPz08IU1vO1JpIyZ0I1txPC9uN155Ij5iPi5oJSIsKVFhP0JxM1svMkphL0VlNzdsOlQxKUQnJF4xPkk9PUczNiF8MzdkNy9sLjg6NCNwIy1sKTw6MA==”),<br> “field9” : BinData(0,”KDRqP1o3KzwgNUlzPjwgJEgtJC44PUUlPkknKU5pLzkuLEAtIlg9JFwpKzBqIzo2MCIoKTxgNU9tIz84OFB/MzJ4PjwoPCYyNj9mOjY+KU09JUk1I0l9O0s/IEUhNU05NShiNg==”),<br> “field8” : BinData(0,”NDFiOj9mJyY6KTskO0A/OVg/NkchKEFtJUprIlJrPjYsKT98JyI8KFwzOEE7ICR4LUF9JkU1KyRkKikoK0g3MEMxKChsL10pKkAvPFRxLkxhOlotJFZlM0N/LiR4PjlqJ0FtOw==”),<br> “field3” : BinData(0,”OSYoJTR+JEp9K00pKj0iITVuIzVqPkBpJFN9Myk4PDhqOjVuP1YhPSM2MFp/Kz14PTF4Mlk3PkhzKlx3L0xtKjkqPCY4JF0vIic6LEx7PVBzI0U9KEM1KDV4NiEuKFx5MiZyPw==”),<br> “field2” : BinData(0,”Njd8LywkPlg9IFl7KlE5LV83ISskPVQpNDYgMEprOkprMy06LlotMUF5LDZ0IldzLl0tJVkjMTdgJkNxITFsNismLDxuIyYoNDgsLTc+OVpzKkBlMDtoLyBgLlctLCxsKzl+Mw==”),<br> “field5” : BinData(0,”OCJiNlI1O0djK1BtIyc4LEQzNj9wPyQiPT8iNE1pODI2LShqNDg4JF1jNiZiNjZuNE5lNzA8OCAgMDp2OVkjNVU3MzIuJTgkNDp0IyVkJyk6IEEvKzVyK1s9PEAhKUJvPDxyOw==”),<br> “field4” : BinData(0,”OFN1I0B7N1knNSR2LFp7PjUyPlJjP15jIUdlN0AhNEkhMC9+Lkd5P10jO1B3K10/I0orIUI1NzYuME81I0Y1NSYkMCxyI0w/LTc8PCEgJUZvMiQiIkIhPCF4LyN6K14rIUJlJg==”)<br>}<br>&gt; db.runCommand({ dbStats: 1, scale: 1 })<br>{<br> “db” : “ycsb”,<br> “collections” : 1,<br> “objects” : 2500000,<br> “avgObjSize” : 1167.8795252,<br> “dataSize” : 2919698813,<br> “storageSize” : 2919698813,<br> “numExtents” : 0,<br> “indexes” : 1,<br> “indexSize” : 76717901,<br> “ok” : 1<br>}</p><p>So the space taken is ~2.7GB. This is pretty close to what we expected.</p><h4>Redis</h4><p>Let’s look at Redis now.</p><p>&gt; info keyspace<br># Keyspace<br>db0:keys=2500001,expires=0,avg_ttl=0<br>127.0.0.1:6379&gt; RANDOMKEY<br>“user3176318471616059981”<br>127.0.0.1:6379&gt; hgetall user3176318471616059981<br> 1) “field1”<br> 2) “#K/&lt;No\”&amp;l*M{,;f;]\x7f)Ss’+2&lt;D}7^a8I/01&amp;9.:)Q71T7,3r&amp;\\y6:&lt; Gk;6n*]-)*f&gt;:p:O=?&lt;:(;v/)0)Yw.W!8]+4B=8.z+*4!”<br> 3) “field2”<br> 4) “(9&lt;9P5**d7&lt;v((2–6*3Zg/.p4G=4Us;N+!C! I50&gt;h=&gt;p\”X9:Qo#C9:;z.Xs=Wy*H3/Fe&amp;0`8)t.Ku0Q3)E#;Sy*C).Sg++t4@7-”<br> 5) “field5”<br> 6) “#1 %8x=’l?5d38~&amp;U!+/b./b;(6-:v!5h.Ou2R}./(*)4!8&gt;\”B’!I)5U?0\” &gt;Ro.Ru=849Im+Qm/Ai(;:$Z’,]q:($%&amp;(=3~5(~?”<br> 7) “field0”<br> 8) “+\”(1Pw.&gt;*=807Jc?Y-5Nq#Aw=%*57r7!*=Tm!&lt;j6%t3–45L5%Cs#/h;Mg:Vo690-/&gt;-X}/X#.U) )f9-~;?p4;p*$&lt; D-1_s!0p&gt;”<br> 9) “field7”<br>10) “:]o/2p/3&amp;(!b&gt; |#:0&gt;#0–9b&gt;Pe6[}&lt;Z{:S}9Uc*0&lt;)?60]37&#39;~’Jk-Li’,x!;.5H’\”’|.!v4Y-!Hk=E\x7f2;8*9((-09*b#)x!Pg2&quot;<br>11) “field3”<br>12) “ C; ,f6Uq+^i Fi’8&amp;0By\”^##Qg\”:$+7$%Y;7Rs’\”d3Km’Es&gt;.|33$ Vo*M%=\”&lt;$&amp;j%/&lt;5]%\”.h&amp;Kc’5.46x5D35&#39;0–3l:\”| !l;”<br>13) “field6”<br>14) “-5x6!22)j;O=?1&amp;!:&amp;.S=$;|//r’?d!W54(j!$:-H5.*n&amp;Zc!0f;Vu2Cc?E{1)r?M’!Kg’-b&lt;Dc*1d2M-9*d&amp;(l?Uk5=8,&gt;0.B#1”<br>15) “field9”<br>16) “(Xa&amp;1t&amp;Xq\”$((Ra/Q9&amp;\”: &amp;&gt;4Ua;Q=!T;(Vi2G+)Uu.+|:Ne;Ry3U\x7f!B\x7f&gt;O7!Dc;V7?Eu7E9\”&amp;&lt;-Vi&gt;7\”$Q%%A%1&lt;2/V11: :^c+”<br>17) “field8”<br>18) “78(8L9.H#5N+.E5=2`&lt;Wk+Pw?+j’Q=3\”$,Nk3O{+3p4K?0/ 5/r:W)5X}#;p1@\x7f\”+&amp;#Ju+Z97#t:J9$’*(K).7&amp;0/` 125O38O)0&quot;<br>19) “field4”<br>20) “$F=)Ke5V15_)-’&gt;=C-/Ka7&lt;$;6r#_u F9)G/?;t&amp; x?D%=Ba Zk+]) ($=I%3P3$&lt;`&gt;?*=*r9M1-Ye:S%%0,(Ns3,0&#39;A\x7f&amp;Y12A/5”<br>127.0.0.1:6379&gt; info memory<br># Memory<br>used_memory:6137961456<br>used_memory_human:5.72G<br>used_memory_rss:6275940352<br>used_memory_rss_human:5.84G<br>used_memory_peak:6145349904<br>used_memory_peak_human:5.72G<br>total_system_memory:7844429824<br>total_system_memory_human:7.31G<br>used_memory_lua:37888<br>used_memory_lua_human:37.00K<br>maxmemory:7516192768<br>maxmemory_human:7.00G<br>maxmemory_policy:noeviction<br>mem_fragmentation_ratio:1.02<br>mem_allocator:jemalloc-3.6.0</p><p>At peak usage, Redis seems to be taking around 5.72 G of memory i.e. <strong>twice as much memory as MongoDB takes.</strong> Now, this comparison may not be perfect because of the differences between the two databases. But the difference is too large to ignore. YCSB inserts records in a hash in Redis. An index is maintained in a sorted set. Since an individual<a href="https://redis.io/topics/memory-optimization#special-encoding-of-small-aggregate-data-types"> entry is larger than 64</a>, the hash is encoded normally, thus there are no space savings there. <strong>Redis performance comes at the price of increased memory footprint.</strong></p><p>This, in our opinion, can be an important data point in choosing between MongoDB and Redis: MongoDB might be of interest to users who care about reducing their memory costs.</p><h3>C: Network Throughput</h3><p>An in-memory database server is liable to either be compute-bound or network I/O-bound. It was thus important throughout the entire set of these tests to ensure that we were never getting network-bound. Measuring network throughput while running application throughput tests adversely affects overall throughput measurement. Thus, we ran subsequent network throughput measurements using<a href="https://en.wikipedia.org/wiki/Iftop"> iftop</a> at the thread counts at which highest write throughputs were observed. This number was found to be around 440 Mbps for both Redis and MongoDB at their respective peak throughput. Given our initial measurement of the maximum network bandwidth to be around 1.29 Gbps, we are certain that we never hit the network bounds. In fact, it only supports the inference that if Redis were multi-core, we might get much better numbers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=724863a4f8bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Resque Usage using Node.js, Websockets, and Redis]]></title>
            <link>https://medium.com/@scalegridio/visualizing-resque-usage-using-node-js-websockets-and-redis-b8cf1a4e6111?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8cf1a4e6111</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Tue, 23 May 2017 18:34:50 GMT</pubDate>
            <atom:updated>2017-05-23T18:34:50.886Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://scalegrid.io/">ScaleGrid</a> is the only <a href="https://scalegrid.io/mongodb/products.html">MongoDB</a> and <a href="https://scalegrid.io/redis/products.html">Redis</a> hosting solution that lets you manage mongo instances on both public clouds and on premise from a single central console. Try us free for 30 days.</h4><p><em>This post was recently published on the </em><a href="https://scalegrid.io/blog/"><em>ScaleGrid blog</em></a><em> and helps you visualize how your Resque queues, workers, and jobs are doing. This blog post teaches you to learn how to build some simple graphs around the Resque components.</em></p><p><em>If you have any questions, please feel free to ask them in the comments section below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d-5aQzAT8xD4ldUDEMePHg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*rLxDgRbuDS1jNZN2OzG_ow.gif" /></figure><h3>Introduction</h3><p>The delegation of long-running, computationally expensive and high latency jobs to a background worker queue is a common pattern used to create scalable web applications. The aim is to serve end-user requests with fastest possible responses, by ensuring that all expensive jobs are handled outside the request/response cycle.</p><h3>Resque</h3><p>Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later. It is designed to be used in scenarios that require a high volume of job entries and provides mechanisms to ensure visibility and reliability of behavior while providing statistics using a web dashboard.</p><h3>Redis</h3><p>Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes with radius queries.</p><h3>Node.js</h3><p>Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, and thus perfect for data-intensive real-time applications that run across distributed devices.</p><h3>Express.js</h3><p>Express.js is a Node.js framework. Node.js is a platform that allows JavaScript to be used outside the web browsers, for creating web and network applications. This means that you can create the server and server-side code for an application like most of the other web languages but using JavaScript.</p><h3>Socket.IO</h3><p>Socket.IO<strong> </strong>is a JavaScript library for real-time web applications. It enables real-time, bi-directional communication between web clients and servers. It has two parts: a client-side library that runs on the browser, and a server-side library for node.js. Both components have nearly identical APIs.</p><h3>Heroku</h3><p>Heroku is a cloud platform that lets companies build, deliver, monitor, and scale apps — it is the fastest way to go from idea to URL, bypassing all those infrastructure headaches.</p><p>This article assumes that you already have Redis, Node.js, and the Heroku Toolbelt installed on your machine.</p><h3>Setup:</h3><ol><li>Download the code from the following repository: <a href="https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-resque/node-socket-resque">https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-resque/node-socket-resque</a></li><li>Run npm install to install the necessary components</li><li>Finally, you can start the node server by doing “node index.js”. You can also run “nodemon” which watches for file changes as well.</li></ol><p>You can also access a hosted version of this app here: <a href="https://node-socket-redis-resque.herokuapp.com/">https://node-socket-redis-resque.herokuapp.com/</a></p><p>Our application uses a port of Resque called <a href="https://github.com/taskrabbit/node-resque">node-resque</a> that allows us to watch queues, workers, and jobs running on a Redis cluster.</p><h3>Understanding the Basics</h3><p>As soon as you start the app, you are required to enter your Redis cluster credentials.</p><p>Please note that you must have Resque installed and running on your cluster for this to work correctly.</p><p>Fortunately, Redis on ScaleGrid provides a high performance, one click, and fully- managed <a href="https://scalegrid.io/redis/products.html">Redis hosting solution</a>.</p><p>If you’re not already a member, you can sign up for a free 30-day trial <a href="https://console.scalegrid.io/users/register">here</a>.</p><p>Otherwise, log in to your dashboard and create a new Redis cluster under the Redis section.</p><p>Once your cluster is up and running, you can pick up the necessary details from the Cluster Details Page. You will need the following info:</p><ol><li>Host</li><li>Port</li><li>Password</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jOOGBS4UHAHe457OOUa5pA.png" /></figure><p>If the connection is successful, you should see graphs like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*36t8ezLssY9uroX8rVALew.png" /></figure><p>Let’s discuss each of these graphs in detail. Please note that all the graphs are self-updating which means that if workers are processing jobs on your cluster, the graphs will update themselves automatically.</p><h3>Total Tasks Across All Queues</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*-G7wh-iPCudnE8DtxD98PA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*96vh9czjFUBkewr0VtNezw.png" /></figure><p>The above graphs show the total number of Resque queues on your cluster and the number of jobs contained in each queue. Resque stores a job queue in a redis list named “resque:queue:name”, and each element in the list is a hash serialized as a JSON string. Redis also has its own management structures, including a “failed” job list. Resque namespaces its data within redis with the “resque:” prefix, so it can be shared with other users.</p><h3>Worker/Jobs Histogram</h3><p>A Resque Worker processes jobs. On platforms that support fork(2), the worker will fork off a child to process each job. This ensures a clean slate when beginning the next job and cuts down on gradual memory growth as well as low-level failures.</p><p>It also ensures that workers are always listening to signals from you, their master, and can react accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*RpsDR7mkvi34QJCIYWqq_w.png" /></figure><p>The above graph shows all the workers on the Redis cluster. A state of 1 indicates that a job has been assigned to the worker and is in progress. A state of 0 indicates that the worker is free/idle.</p><h3>Job Status</h3><p>A Resque Job represents a unit of work. Each job lives on a single queue and has an associated payload object. The payload is a hash with two attributes: `class` and `args`. The `class` is the name of the Ruby class which should be used to run the job. The `args` are an array of arguments which should be passed to the Ruby class’s `perform` class-level method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*2s_Ra8Z3De5mm3EdpLpG8g.png" /></figure><p>The above graph shows the status of jobs as processed or failed. A job is added to the failed state if the worker has failed to execute it. Here is an example of a simple Jobs Object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Hlba1LxHusFECvRHWCAPQ.png" /></figure><p>A hosted version is available here: <a href="https://node-socket-redis-resque.herokuapp.com/">https://node-socket-redis-resque.herokuapp.com/</a></p><p>For deploying this application on Heroku, check out their docs: <a href="https://devcenter.heroku.com/categories/deployment">https://devcenter.heroku.com/categories/deployment</a></p><p>The entire source code is also available on GitHub for you to fork and work on: <a href="https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-resque/node-socket-resque">https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-resque/node-socket-resque</a></p><p>As always, if you build something awesome, do tweet us about it <a href="https://twitter.com/scalegridio">@scalegridio</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8cf1a4e6111" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Perils of Building Indexes on MongoDB]]></title>
            <link>https://medium.com/@scalegridio/the-perils-of-building-indexes-on-mongodb-f002319dbaa5?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/f002319dbaa5</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Mon, 27 Mar 2017 19:29:30 GMT</pubDate>
            <atom:updated>2017-03-27T19:29:30.227Z</atom:updated>
            <content:encoded><![CDATA[<h4>ScaleGrid is the only <a href="https://scalegrid.io/">MongoDB hosting</a> solution that lets you manage mongo instances on both public clouds and on premise from a single central console. Try us free for 30 days.</h4><p><em>This post was originally featured in February 2017 on the </em><a href="https://scalegrid.io/blog/the-perils-of-building-indexes-on-mongodb/"><em>ScaleGrid blog</em></a><em> and discusses why indexes are a critical part of database operations and the pitfalls you should be aware about for your daily operations when it comes to creating indexes in MongoDB.</em></p><p><em>If you have any other points to share, please do so in the comments section below.</em></p><p>Indexes are a critical part of any database operation. Defining the right indexes can make a huge difference to the performance of your database servers. However, creating indexes in MongoDB has several pitfalls that you need to be aware of for your day to day operations. MongoDB at a high level supports three techniques to build indexes on your collections.</p><h3><strong>1. Foreground Index Build</strong></h3><p>When you build an index in the foreground it blocks all other operations on the database — on a large collection, this can be several hours. This implies that your database is down for the duration of the index build. Given that this is the default mode of building indexes it is not surprising that a lot of developers shoot themselves in the foot triggering accidental index builds. There is really no good reason to trigger a foreground index build on a production server (unless you know that the collection has a small amount of data).</p><h3>2. Background Index Build</h3><p>As the name implies the background indexing process builds the index in the background without affecting the availability of your database server. However, it is still a resource intensive operation and you should expect to see performance degradation. Also since it is happening in the background it can take a lot longer to build than the foreground indexes. In the previous versions of MongoDB (&lt; 2.6) when you did a background index build on the primary of a replica set it would run as “foreground” build on the secondary servers, thankfully it is no longer the case — it is background build on all the nodes. If a background index build is interrupted it will resume as a foreground index build on server restart.</p><h3>3. Rolling Index Build</h3><p>The rolling index build process builds the index on only one node at a time. It goes something like this<br>1. Rotate a secondary node out of the replica set (you can do this by changing ports or restarting in standalone mode)<br>2. Build the index on this node in the foreground. Once the index is built, rotate the node back into the replica set<br>3. Once the node has caught up to the changes move on to the next node. If the next node is the primary you will need to do a rs.stepDown() to make it into a secondary.<br>4. Rinse and repeat.</p><p>More details of the index build process are in the <a href="https://docs.mongodb.com/manual/tutorial/build-indexes-on-replica-sets/#index-building-replica-sets">MongoDB documentation</a>.</p><p>Using rolling index builds you can build an index without any significant performance impact for your application. However there is failover involved — so your application should be able to handle that (which it needs to anyways).</p><p>Can you do a rolling index build if you don’t have a replica set? Unfortunately for standalone instances, the only option is a “Background index build”.</p><p>The Rolling index build is our favored approach to building indexes at ScaleGrid. We even provide a UI and make it easy for you to kick off the whole process from our UI. Our backend will do all the orchestration necessary for the full index build — it will trigger a server by server index build. You just need to <a href="https://scalegrid.io/pricing.html">get setup with us</a> and then point and click!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lwFNVAeOU878TjycFEv34w.png" /></figure><p>As always, if you have further questions you can reach out to us at support@scalegrid.io.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f002319dbaa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Real-Time Chat Bot]]></title>
            <link>https://medium.com/@scalegridio/how-to-build-a-real-time-chat-bot-37a1f056463?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/37a1f056463</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Tue, 21 Feb 2017 16:58:01 GMT</pubDate>
            <atom:updated>2017-02-21T16:58:01.378Z</atom:updated>
            <content:encoded><![CDATA[<h4>ScaleGrid is the only MongoDB and <a href="https://scalegrid.io/redis/products.html">Redis hosting</a> solution that lets you manage mongo and Redis instances on both public clouds and on premise from a single central console. Try us free for 30 days.</h4><p><em>This post was originally featured in January 2017 on the </em><a href="https://scalegrid.io/blog/using-redis-with-node-js-and-socket-io/"><em>ScaleGrid blog</em></a><em> and quickly became a popular post. In this article, we will show you how to build a real-time chat application using Redis, Node.js + Express.js, Socket.IO, and Heroku.</em></p><p><em>If you have any other points to share, please do so in the comments section below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RlKP8lNmoVjFYzwzj6IyjA.jpeg" /></figure><p>In this article, we will show you how to build a real-time chat application using the following technologies:</p><ul><li>Redis</li><li>Node.js + Express.js</li><li>Socket.IO</li><li>Heroku</li></ul><p><strong>Redis</strong> is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes with radius queries.</p><p>In this application, we will be connecting to one of the clusters hosted on ScaleGrid.</p><p><strong>Node.js</strong> is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, and thus perfect for data-intensive real-time applications that run across distributed devices.</p><p><strong>Express.js</strong> is a Node.js framework. Node.js is a platform that allows JavaScript to be used outside the web browsers, for creating web and network applications. This means that you can create the server and server-side code for an application like most of the other web languages but using JavaScript.</p><p><strong>Socket.IO</strong> is a JavaScript library for realtime web applications. It enables real-time, bi-directional communication between web clients and servers. It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Both components have nearly identical APIs.</p><p><strong>Heroku</strong> is a cloud platform that lets companies build, deliver, monitor and scale apps — it is the fastest way to go from idea to URL, bypassing all those infrastructure headaches.</p><p>This article assumes that you already have Redis, Node.js and the Heroku Toolbelt installed on your machine.</p><h3>Setup</h3><p>Create a folder and give it a name. You can create it anywhere on your machine since Node.js does not need a special server like Apache/nginx.</p><h3>Step 1</h3><p>Initialize a package.json file by running npm init.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBpFqRY_ZmKa1deojLaeyA.png" /></figure><h3>Step 2</h3><p>Install the following dependencies:</p><ul><li><a href="http://expressjs.com/">expressjs</a></li><li><a href="http://socket.io/">socketio</a></li><li><a href="https://github.com/NodeRedis/node_redis">redis</a></li></ul><p>…and some other utility methods:</p><ul><li><a href="https://github.com/expressjs/body-parser">body-parser</a></li></ul><p>by running the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjaglOeBQHvcl7YzsrBX6A.png" /></figure><h3>Step 3</h3><p>Create a public folder for storing our CSS and JS files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kQO3qea7blqywD2tODiTw.png" /></figure><h3>Step 4:</h3><p>Create a views folder for storing our main HTML file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cnUZRijGSWRsvvG597jUvw.png" /></figure><h3>Step 5:</h3><p>Create a creds.json file that will contain the credentials for connecting to our Redis Cluster. It should follow the following format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fcsL0rQiNWznC6gbIMXD8A.png" /></figure><h3>Step 6:</h3><p>Create the index.js file that will host our Node.js code and will serve as a starting point for Heroku.</p><h3>Step 7:</h3><p>Add a .gitignore file so the node_modules folder is not checked in to Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJEA4dtrwCXa1YkwO-owhQ.png" /></figure><p>After the end of Step 7, you should have the following structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8gJU7mSE4NZO40EVXOe0PQ.png" /></figure><h3>Step 8</h3><p>Now that everything is setup, we can start writing our backend code. First of all, we need to bring all our modules in. So, open up the index.js file and paste the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REENSANf__r4wnBPaAnu3Q.png" /></figure><p>Before we can start writing any code, we need a cluster running Redis. Fortunately, Redis on ScaleGrid provides a high performance, one click and fully managed Redis-as-a-service solution.</p><p>If you’re not already a member, you can sign up for a free 30-day trial <a href="https://console.scalegrid.io/users/register">here</a>.</p><p>Otherwise, log in to your dashboard and create a new Redis cluster under the Redis section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzOBAtS_4Jtj3mXGt9Au3Q.png" /></figure><p>Once the cluster creation is complete, make note of the above information and add it to the relevant fields of the creds.json file.</p><p>Now that we have our credentials setup, we are ready to create our Redis client in Node that will connect to our cluster and start storing key-value pairs.</p><p>Add the following code to the index.js file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2XwOle-Lub5Glvcp59Y6g.png" /></figure><p>The above code does two things:</p><ol><li>Reads the credentials from creds.json and creates a Redis client that is used to perform key-value operations</li><li>Once the client is ready, we populate the chatters and the chat_messages so any new members that join will be able to see the chat history.</li></ol><p>We are now going to write a couple of APIs to handle the chat application. We need the following APIs:</p><ul><li>Join Room [POST]</li><li>Leave Room [POST]</li><li>Send Message [POST]</li><li>Get Messages [GET]</li><li>Get Members [GET]</li></ul><p>Let’s start with the Join Room API. This is called when any new user first starts the application and tries to join the chat room.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ui1sxUifIsdG-3q-ERuFww.png" /></figure><p>Here we have the API for leaving the chat room:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bDBDtjRGVBg_8nwb5z9jNQ.png" /></figure><p>Sending and storing the message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81xlxNHhOTdtz1JsWgJ0mA.png" /></figure><p>Get all messages in room:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*poBaayvFXrt3kXavK_TvcA.png" /></figure><p>Get all members:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BpmBu7tS3uxedSpqMipcBA.png" /></figure><p>Once we have all the APIs set up, we need to write socket.io code to emit events when certain properties such as the following get updated:</p><ul><li>Room Count</li><li>Messages</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPysVxPVi36LeDJBfC49Qw.png" /></figure><p>These events are then picked up on the front-end by the socket.IO library which in turn updates the UI.</p><h3>Step 9</h3><p>Now, we need to build our UI that will allow users to sign in and chat.</p><p>Open up the index.html file and add the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFI4JSf36Z86xZXkM_YurQ.png" /></figure><h3>Step 10</h3><p>To make our HTML work, we need to add some JavaScript AJAX events that will handle the various operations like joining a room, leaving, sending a message etc.</p><p>The following code gets the number of chatters so we can update the UI about the total number of people in the room:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wu2aZpmOxFR-HPD5WSFPQ.png" /></figure><p>This code allows users to join the chat room. Usernames are unique and cannot be duplicated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNGRT4ES3a31E-08OBRUZQ.png" /></figure><p>Here is the code for allowing users to leave the chat room:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVYpMJuTGkgIRz9b363YDQ.png" /></figure><p>Here is the code that runs every time someone sends a message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T56vWshy6M0GhPvWbAokzw.png" /></figure><p>The following is the socket.IO code that listens for events from the backend and updates the UI. For example, adding new messages to the messages area, updating the chatter count etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TwbhgJZg4VeKgwAWZE_uCA.png" /></figure><p>And you’re done! Fire up the server using npm start and open multiple browser windows to simulate multiple users.</p><p>A demo of the application is available here: <a href="https://node-socket-redis-chat.herokuapp.com/">https://node-socket-redis-chat.herokuapp.com/</a></p><p>For deploying this application on Heroku, check out their docs: <a href="https://devcenter.heroku.com/categories/deployment">https://devcenter.heroku.com/categories/deployment</a></p><p>The entire source code is also available on GitHub for you to fork and work on: <a href="https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-chat/redis-node-socket-chat">https://github.com/Scalegrid/code-samples/tree/sg-redis-node-socket-chat/redis-node-socket-chat</a></p><p>As always, if you build something awesome, do tweet us about it <a href="https://twitter.com/scalegridio">@scalegridio</a></p><p>If you need help with <a href="https://scalegrid.io/redis/products.html">Redis hosting</a> and management, let us simplify things for you with our professional services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37a1f056463" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Infographic] Comparing Cassandra vs. MongoDB]]></title>
            <link>https://medium.com/@scalegridio/infographic-comparing-cassandra-vs-mongodb-7f55723c671b?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f55723c671b</guid>
            <category><![CDATA[infographics]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Tue, 27 Dec 2016 21:01:35 GMT</pubDate>
            <atom:updated>2016-12-27T21:01:35.063Z</atom:updated>
            <content:encoded><![CDATA[<h4>ScaleGrid is the only <a href="https://scalegrid.io/">MongoDB hosting</a> solution that lets you manage mongo instances on both public clouds and on premise from a single central console. Try us free for 30 days.</h4><p><em>We wrote about Cassandra vs. MongoDB in August 2016 on the </em><a href="https://scalegrid.io/blog/cassandra-vs-mongodb/"><em>ScaleGrid blog</em></a><em> which quickly became a popular post. Due to the popularity, we created an infographic to supplement the post.</em></p><p><em>We thought we would make it even easier to consider the pros and cons of choosing one database over another. Below is a slimmed down comparison plus a verdict for each comparison that will help you choose based on your needs. However, if you need a more in-depth look at the differences between the two databases, head to the </em><a href="https://scalegrid.io/blog/cassandra-vs-mongodb/"><em>original blog post</em></a><em>.</em></p><p><em>This infographic was originally featured on the </em><a href="https://scalegrid.io/blog/infographic-comparing-cassandra-vs-mongodb/"><em>ScaleGrid blog</em></a><em> in December 2016.</em></p><p><em>If you have any other points to help compare and contrast Cassandra and MongoDB, please share in the comments section below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*Z3w_pkEfvQtef3JN6gdAOg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f55723c671b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cassandra vs. MongoDB]]></title>
            <link>https://medium.com/@scalegridio/cassandra-vs-mongodb-d6930cd7e512?source=rss-75cb4bf85e95------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6930cd7e512</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Scalegrid.io]]></dc:creator>
            <pubDate>Wed, 12 Oct 2016 16:09:06 GMT</pubDate>
            <atom:updated>2016-10-12T16:09:06.085Z</atom:updated>
            <content:encoded><![CDATA[<h4>ScaleGrid is the only <a href="https://scalegrid.io/">MongoDB hosting</a> solution that lets you manage mongo instances on both public clouds and on premise from a single central console. Try us free for 30 days.</h4><p><em>This post was originally featured in August 2016 on the </em><a href="https://scalegrid.io/blog/cassandra-vs-mongodb/"><em>ScaleGrid blog</em></a><em> and quickly became a popular post.</em></p><p><em>We discuss key qualities which differentiate Cassandra from MongoDB, including: expressive objective model, secondary indexes, high availability, write scalability, query language support, performance benchmarks, ease of use, native aggregation, and schema-less models. We also highlight helpful verdicts after some of the points for you for quick reference.</em></p><p><em>If you have any other points to help compare and contrast Cassandra and MongoDB, please share in the comments section below.</em></p><p>Are you considering Cassandra or MongoDB as the data store for your next project? Would you like to compare the two databases? Cassandra and MongoDB are both “NoSQL” databases, but the reality is that they are very different. They have very different strengths and value propositions — so any comparison has to be a nuanced one.</p><p>Let’s start with initial requirements…Neither of these databases replace RDBMS, nor are they “ACID” databases. So if you have a transactional workload where normalization and consistency are the primary requirements, neither of these databases will work for you. You are better off sticking with traditional relational databases such as MySQL, PostGres, Oracle, etc.</p><p>Now that we have relational databases out of the way, let’s consider the major differences between Cassandra and MongoDB that will help you make the decision. In this post, I am not going to discuss specific features, but will point out some high-level strategic differences to help you make your choice.</p><h3>1. Expressive Object Model</h3><p>MongoDB supports a rich and expressive object model. Objects can have properties and objects can be nested in one another (for multiple levels). This model is very “object oriented” and can easily represent any object structure in your domain. You can also index the property of any object at any level of the hierarchy — this is strikingly powerful! Cassandra, on the other hand, offers a fairly traditional table structure with rows and columns. Data is more structured and each column has a specific type which can be specified during creation.</p><h3>Verdict: If your problem domain needs a rich data model then MongoDB is a better fit for you.</h3><h3>2. Secondary Indexes</h3><p>Secondary indexes are a first class construct in MongoDB. This makes it easy to index any property of an object stored in MongoDB even if it is nested. This makes it easy to query based on these secondary indexes. Cassandra has only cursory support for secondary indexes. Secondary indexes are also limited to single columns and equality comparisons. If you are mostly going to be querying by the primary key then Cassandra will work well for you.</p><h3>Verdict: If your application needs secondary indexes and needs flexibility in the query model then MongoDB is a better fit for you.</h3><h3>3. High Availability</h3><p>MongoDB supports a “single master” model. This means you have a master node and a number of slave nodes. In case the master goes down, one of the slaves is elected as master. This process happens automatically but it takes time, usually 10–40 seconds. During this time of new leader election, your replica set is down and cannot take writes. This works for most applications but ultimately depends on your needs. Cassandra supports a “multiple master” model. The loss of a single node does not affect the ability of the cluster to take writes — so you can achieve 100% uptime for writes.</p><h3>Verdict: If you need 100% uptime Cassandra is a better fit for you.</h3><h3>4. Write Scalability</h3><p>MongoDB with its “single master” model can take writes only on the primary. The secondary servers can only be used for reads. So essentially if you have three node replica set, only the master is taking writes and the other two nodes are only used for reads. This greatly limits write scalability. You can deploy multiple shards but essentially only one-third of your data nodes can take writes. Cassandra with its “multiple master” model can take writes on any server. Essentially your write scalability is limited by the number of servers you have in the cluster. The more servers you have in the cluster, the better it will scale.</p><h3>Verdict: If write scalability is your thing, Cassandra is a better fit for you.</h3><h3>5. Query Language Support</h3><p>Cassandra supports the CQL query language which is very similar to SQL. If you already have a team of data analysts they will be able to port over a majority of their SQL skills which is very important to large organizations. However, CQL is not full blown ANSI SQL — it has several limitations (no join support, no OR clauses, etc). MongoDB at this point has no support for a query language. The queries are structured as JSON fragments.</p><h3>Verdict: If you need query language support, Cassandra is the better fit for you.</h3><h3>6. Performance Benchmarks</h3><p>Let’s talk performance. At this point, you are probably expecting a performance benchmark comparison of the databases. I have deliberately not included performance benchmarks in the comparison. In any comparison, we have to make sure we are making an apples-to-apples comparison.</p><ol><li><strong>Database model </strong>— The database model/schema of the application being tested makes a big difference. Some schema’s are well suited for MongoDB and some are well suited for Cassandra. So when comparing databases it is important to use a model that works reasonably well for both databases.</li><li><strong>Load characteristics</strong> — The characteristics of the benchmark load are very important. E.g. In write-heavy benchmarks, I would expect Cassandra to smoke MongoDB. However, in read-heavy benchmarks, MongoDB and Cassandra should be similar in performance.</li><li><strong>Consistency requirements</strong> — This is a tricky one. You need to make sure that the read/write consistency requirements specified are identical in both databases and not biased towards one participant. Very often in a number of the ‘Marketing’ benchmarks the knobs are tuned to disadvantage the other side. So pay close attention to the consistency settings.</li></ol><p>One last thing to keep in mind is that the benchmark, load may or may not reflect the performance of your application. So in order for benchmarks to be useful, it is very important to find a benchmark load that reflects the performance characteristics of your application.</p><p>Here are some benchmarks you might want to look at: <a href="https://www.mongodb.com/scale/nosql-performance-benchmarks">https://www.mongodb.com/scale/nosql-performance-benchmarks</a><a href="http://www.datastax.com/nosql-databases/benchmarks-cassandra-vs-mongodb-vs-Hbase">http://www.datastax.com/nosql-databases/benchmarks-cassandra-vs-mongodb-vs-Hbase</a></p><h3>7. Ease of Use</h3><p>If you had asked this question a couple of years ago MongoDB would be the hands down winner. It’s a fairly simple task to get MongoDB up and running. In the last couple of years, however, Cassandra has made great strides in this aspect of the product. With the adoption of CQL as the primary interface for Cassandra it has taken this a step further — they have made it very simple for legions of SQL programmers to use Cassandra easily.</p><h3>Verdict: Both are fairly easy to use and ramp up.</h3><h3>8. Native Aggregation</h3><p>MongoDB has a built in aggregation framework to run an ETL pipeline to transform the data stored in the database. This is great for small to medium jobs, but as your data processing needs become more complicated the aggregation framework becomes difficult to debug. Cassandra does not have a built-in aggregation framework. External tools like Hadoop and Spark are used for this.</p><h3>9. Schema-less Models</h3><p>In MongoDB, you can choose to not enforce any schema on your documents. While this was the default in prior versions in the newer version you have the option to enforce a schema for your documents. Each document in MongoDB can be a different structure and it is up to your application to interpret the data. While this is not relevant to most applications, in some cases the extra flexibility is important. Cassandra in the newer versions (with CQL as the default language) provides static typing. You need to define the type of very column upfront.</p><p><strong>To summarize here are the important differences in table form:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*IqD4iTIhQMyiqsClV5jZpw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6930cd7e512" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>