<?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 Arnout Kazemier on Medium]]></title>
        <description><![CDATA[Stories by Arnout Kazemier on Medium]]></description>
        <link>https://medium.com/@3rdeden?source=rss-312e88c6f685------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rYJ8Y3WwuxOZee3M.jpeg</url>
            <title>Stories by Arnout Kazemier on Medium</title>
            <link>https://medium.com/@3rdeden?source=rss-312e88c6f685------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:47:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@3rdeden/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[Cluster fucks when scaling Socket.IO]]></title>
            <link>https://medium.com/@3rdeden/cluster-fucks-when-scaling-socket-io-2c8ad1153332?source=rss-312e88c6f685------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c8ad1153332</guid>
            <dc:creator><![CDATA[Arnout Kazemier]]></dc:creator>
            <pubDate>Fri, 07 Mar 2014 20:51:27 GMT</pubDate>
            <atom:updated>2014-03-07T20:59:14.599Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or why all Socket.IO store based modules are fundamentally broken.</h4><p>When Socket.IO 0.7 got released it was a complete rewrite of the old Socket.IO code and came with a new concept called stores. It was said to be the magical scale sauce that would allow you to scale to multiple processes and servers by changing the <em>store</em> option. Heck, you could even scale without needing a sticky load balancer because they are so hard to setup, right? Socket.IO shipped with a <em>MemoryStore</em> by default and there was work done on a <em>RedisStore</em> that would make the multiple processes scaling possible using the build-in Pub/Sub channels of Redis.</p><p>The RedisStore was <strong>never</strong> formally announced but people started using it anyways as it was getting advised on StackOverFlow and other message boards. The community picked up the store concept and started building bindings to other message queues and databases such as <a href="https://npmjs.org/package/socket.io-store-memcached">Memcached</a>, <a href="https://npmjs.org/package/socket.io-mongo">MongoDB</a>, <a href="https://npmjs.org/package/socket.io-zero">ØMQ</a>, <a href="https://npmjs.org/package/socket.io-servicebus">Azure Servicebus</a> and even many more which all worked through the Socket.IO store interface.</p><p>The store concept of Socket.IO is build on the idea of syncing all the connection data between every connected node within your cluster. It doesn’t matter which kind of store you are using in Socket.IO as they are all using this concept as it’s build in to Socket.IO store interface, not the stores that you are using. If you didn’t already throw up in mouth a bit when you read the word <strong>syncing</strong>, I’ll explain a the issues a bit in closer depth.</p><p>So in order to understand why syncing is bad for Socket.IO stores we first need to know what is synced. We can find this information in the <a href="https://github.com/LearnBoost/socket.io/blob/0.9.14/lib/manager.js#L282-L323">initstore</a> function of the Socket.IO manager. So this is:</p><p>- Handshake data, the handshake data includes ALL request headers, query strings, ip address, information, urls and possible custom data that you’ve added during authorization.<br>- Ids of all connections that are open, connected and even closed.<br>- Room names and each id that has joined the room.</p><p>All this data will be synced through pub/sub to every connected Socket.IO server. So if you have 2 node process and they both use Socket.IO stores they will both have all the data of all connections in their own process memory. Not in redis as you might assume. It might not be an issue if you have 500 connected users, but once you approach 5.000&gt; connections this can add up quickly.</p><p>If you’ve carefully read and start to understand this concept, it can actually be used as an attack vector against Socket.IO servers which are connected using the Socket.IO stores. The attacker only needs to create a script that initiates a handshake request with your server which connects with the longest query string allowed with as much custom HTTP headers possible and you could easily blow up a server in a matter seconds because all this data is serialized using JSON.stringify which will start blocking the event loop for all the serialization and when you receive such a large packet it also needs to parsed again by JSON.parse and eventually it will be stored in the V8 heap of your node’s process. This will eventually cause it explode out of memory due to the V8 heap limitations of 1.7 GB and your whole cluster will be <a href="http://en.wikipedia.org/wiki/Military_slang#FUBAR">FUBAR</a>.</p><p>But storing data isn’t the only problem. Usually when you want to scale out you just want to be able to add new servers without taking your whole cluster down. This is impossible with Socket.IO. When you add a new server you need take your whole cluster down because the synced data is not stored in a general location. It’s only stored in the process’s heap, and when you join the cluster it doesn’t ask the other node processes for the old data so it’s a completely blank and empty server and can therefor not accept them and will close the connection with a “unknown handshake” error. The only way to combat this is to take your whole cluster down. Add new node processes/servers, bring them all online at the same time and start accepting connections again.</p><p>The following issue might or might not be specific to the Redis store but it’s worth mentioning anyways. For every connection that is established the store will subscribe to <strong>5</strong> different channels. So if you have 10000 concurrent connections you will also have 50000 subscriptions to your redis server which causes redis to use a magnitude more CPU than if it would just use single or a couple of channels to communicate over for ever connection.</p><p>So again, let me make this really clear: These issues are not related to just RedisStore that ships in Socket.IO. This is the problem for <strong>EVERY</strong> store that uses Socket.IO’s store interface. Scaling your servers using a sticky load balancer with a custom store/broadcast solution should start to sound really tempting by now.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c8ad1153332" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An attack on  publisher freedom]]></title>
            <link>https://medium.com/@3rdeden/an-attack-on-publisher-freedom-271013ff33c5?source=rss-312e88c6f685------2</link>
            <guid isPermaLink="false">https://medium.com/p/271013ff33c5</guid>
            <dc:creator><![CDATA[Arnout Kazemier]]></dc:creator>
            <pubDate>Wed, 26 Feb 2014 13:33:16 GMT</pubDate>
            <atom:updated>2014-02-26T16:08:09.329Z</atom:updated>
            <content:encoded><![CDATA[<h4>and the power abuse by npm Inc.</h4><p>When you are working with Node.js you are probably also working with <em>npm</em>, the package manager that is shipped in with the <em>node</em> distribution. The npm Registry is where we, as Open Source developers release all our modules for people to use freely. We enjoy sharing the fruits of our labour and like to give back to community. But releasing your code isn’t that easy. There are already more than <strong>60.000</strong> Open Source packages in The npm Registry so you’re lucky to find a module name that fits the use case of your module as a lot of good names are already taken.</p><h4>npmjs</h4><p>I’ve have recently started working on a new Open Source module for The npm Registry. This module is an alternate and in my opinion a better API for The npm Registry. If you want to communicate with The npm Registry you could either use CouchDB directly or use the exposed API that is rewritten by CouchDB. The main reason for writing a competitor to the <em>npm-registry-client</em> module was that I wanted something more sane (for my tastes anyway) while working with the data that is available in The npm Registry. So I packed it with features that I needed to work with npm so it’s highly opinionated and exposes a completely different but in my opinion more readable API and it ensures a stable normalised data structure for all returned results.</p><p>Once I implemented the most core functionality I was ready to release it to The npm Registry so other developers could use the fruits of my labour to build amazing applications and modules on top of it. But it needed a name. I’ve always been fan of simplicity, I prefer one word names over multiple-words-to-describe-a-module. This makes it easier for people to remember the name and results in smaller and more human readable code. So after a search for various of keywords I found out that the module name <strong>npmjs</strong> was still available in the registry. In the four years that the registry existed nobody took the effort in registering it. This module was and is a perfect fit for my module as interacts with the registry that is accessible on <a href="https://registry.npmjs.org./">https://registry.npmjs.org.</a> So I released this module and all was well and started implementing the module into various of personal as well as work related projects.</p><h4>Confusing confusion</h4><p>On the 22th I received an email from Isaac, the CEO of npm Inc (which recently <a href="http://techcrunch.com/2014/02/11/npm/">raised more than 2M in funding</a> for his company) and creator of <a href="https://github.com/npm/npm">npm</a> with a <strong>question</strong>:</p><blockquote><strong>Subject:</strong> “npmjs” package on npm registry</blockquote><blockquote>Can you please choose another name for this module? It’s extremely confusing.<br>Thanks.</blockquote><p>Isaac states that the name <em>npmjs</em> is <strong>extremely confusing</strong>. I failed to understand how this simple module has became extremely confusing after releasing it.</p><p>The name, npmjs was unregistered, unused and unnoticed for the last <strong>four</strong> years. Not for a week, no, for a staggering four years. If there was confusing about installing <em>npm</em> vs <em>npmjs</em> for users it would have surely be noticed within these years. A quick search of the Github repository showed that <strong>nobody</strong> has <strong>ever</strong> reported this nor did I find any references or shout outs on twitter about so said <strong>extreme confusing</strong> that this module was causing because there simply isn’t any confusion.</p><p>I did not do any name squatting, it was legitimate module with an appropriate name. The README and package.json of my module all clearly stated this it was an alternate npm registry client. In addition to that there were already modules in The npm Registry that also used npm and npmjs in their names and description. So I replied to Isaac with this information, stating that I did not see a reason to change the name because the <strong>NEVER</strong> was any confusing about the name:</p><blockquote>Hello Isaac,<br>I personally don’t see the problem here. The name was unregistered in the registry so I assumed that has been unused for the last four years that the npm registry has existed. If it was confusing before in these previous, I’m pretty sure someone would have registered that module before for the obvious reasons.</blockquote><blockquote>It’s an appropriate name for the module as well as it’s an alternative npmjs.org api client as clearly stated in the module’s description and it will be actively maintained and implemented as a base for various of npm related modules that I’m currently or will be writing in the near future. I think that this will boost the npm eco system in a good way as it will be easier to write modules that hit the various of npm endpoints.</blockquote><blockquote>So with this all in mind I won’t be changing the modules name because there simply isn’t any reason for it to do so.<br>Kind regards,<br>Arnout</blockquote><h4>Infringing on what?</h4><p>Within a couple of hours I received a reply from Isaac.</p><blockquote>You’re using a name that is the intellectual property of someone else. Even if it wasn’t my mark you were using in a confusing manner, as an admin of the public npm registry, I’d call that bad behaviour at least.<br>I’m not requesting. This isn’t a negotiation. I’m informing you that the “npmjs” module will be deleted from the registry.<br>Please pick a new name that more clearly describes what this module is, and doesn’t imply affiliation between you and npm.<br>Thank you.</blockquote><p>As far as I was aware the name <em>npmjs</em> was <strong>never</strong> protected. The registry is called The npm Registry. Not npmjs, not The npmjs Registry. The only thing that my module name had in common was the domain name and as far as I know, a domain name isn’t considered an intellectual property.</p><p>The most disrupting thing about this email is that Isaac states that me using npmjs in my module name is something that he sees as <strong>bad behaviour</strong>. How is it bad behaviour that I spend my own personal time writing a completely new module that interacts with your API for free and release it as Open Source to boost <strong>your ecosystem </strong>so it’s easier to other authors to work with your service. I would be flattered if someone took their time to write and release code that used my service.</p><p>It didn’t even matter what how right or wrong I was for using npmjs as a module name Isaac had clearly already decided to destroy the module as he stated there wasn’t any negotiation and that it would be deleted no matter what.</p><h4>Coincidence?! I think not!</h4><p>I wondered if he could just simply delete modules from The npm Registry at his own choosing. I couldn’t remember reading this the legal information of npm. The reason that I didn’t remember it is because Isaac changed the legal information to include:</p><blockquote>Any data published to The npm Registry (including user account information) may be removed or modified at the sole discretion of the npm server administrators.</blockquote><p><a href="https://github.com/npm/npm/commit/012da034625d8aa6c3370e6c1c8cbb5cbb30fb41">This change was added on the 17th</a>, just a couple of days before he send me an email. <a href="http://www.youtube.com/watch?v=IRoh62wRgkc">Coincidence? I think not!</a></p><p>He said that I needed to choose a new name for this module that doesn’t imply any affiliation with npm. So this basically means I had to describe my in such a way that it doesn’t use npm or npmjs as they both clearly assume affiliation according to Isaac. And this is just something that I refuse to do.</p><h4>Instantly deleted</h4><p>The final blow for me was when I found out that during the weekend and just hours after our last contact it was deleted! There never was any notice of a date when I could have expected my module to be removed from The npm Registry. It was simply instantly removed.</p><p>Even if the module was to be removed without debate, doing so without notice caused all the modules that were using my module to break. This forced me to work during the weekend to fix the (now) broken code and their dependent deployments. This was time I would had spend with my family and kids instead. Time that I would have had if I had gotten even a little personal consideration or empathy from Isaac.</p><p>The message that Isaac and npm Inc. sends with this is clear to me. We do not give a fuck about our module authors and the modules they release in <strong>our</strong> registry. And we will delete your module without giving you time to update your code as we simply do not care.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=271013ff33c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build first, decide later]]></title>
            <link>https://medium.com/the-build/build-first-decide-later-22af5c94a922?source=rss-312e88c6f685------2</link>
            <guid isPermaLink="false">https://medium.com/p/22af5c94a922</guid>
            <dc:creator><![CDATA[Arnout Kazemier]]></dc:creator>
            <pubDate>Fri, 05 Jul 2013 08:16:56 GMT</pubDate>
            <atom:updated>2013-07-05T14:16:48.679Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing, Primus a real-time server abstraction.</h4><p>You’re about to build your first real-time application and are excited about it. You start researching the different kind of open source frameworks that should make it a breeze for you, but you’re overwhelmed by the possibilities.</p><p>Should you choose <a href="http://github.com/sockjs">SockJS</a>, <a href="http://github.com/learnboost/engine.io">Engine.IO</a> or maybe just use pure <a href="http://github.com/einaros/ws">WebSockets</a>. It’s a hard decision to make as you know you’ll be locked in with that framework as you’re building your application on top of that API. But do you really need to be locked in?</p><p>The biggest problems always happen when you deploy your application to production servers. This is when they receive large quantities of traffic and small bugs can lead to major disasters. Wouldn’t it be nice to be able to switch between real-time servers when they are the source of your issues without having to rewrite your application?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*PZZPTuZUudLIm7SW.jpeg" /><figcaption>Primus, the creator god from the Transformers series.</figcaption></figure><p>Those were some of the reasons why I’ve built <a href="http://github.com/3rd-Eden/primus">Primus</a>. It’s a lightweight wrapper around various real-time frameworks and provides you with one single, low level and <a href="http://nodejs.org/api/stream.html">stream</a> compatible interface for both the server and the client.</p><p><strong>Primus currently supports:</strong></p><p><a href="https://github.com/3rd-Eden/primus#engineio">Engine.IO</a>, <a href="https://github.com/3rd-Eden/primus#socketio">Socket.IO</a>, <a href="https://github.com/3rd-Eden/primus#websockets">WebSockets</a>, <a href="https://github.com/3rd-Eden/primus#browserchannel">Browserchannel</a> and <a href="https://github.com/3rd-Eden/primus#sockjs">SockJS</a>.</p><h3>Getting started with Primus</h3><p>Primus doesn’t have any dependencies on real-time frameworks, keeping it as lightweight as possible. It doesn’t help anyone if we bundled all 5 frameworks. So this does mean that there are 2 modules you need to install, <em>primus</em> and the framework you want to try out first. In this example we’re just going to build a pure WebSocket based application so we need to install <strong>primus</strong> and <strong>ws</strong>:</p><pre>npm install primus<br>npm install ws</pre><p>Once these modules are installed we can start building our application. Primus needs to be attached to a HTTP or HTTPS server. I would advise you to use a <strong>HTTPS</strong> server as it helps prevent possible <a href="https://speakerdeck.com/3rdeden/realtimeconf-dot-oct-dot-2012">connection blocking by proxy servers</a>. Most people don’t run HTTPS inside Node.js as it’s slower than a HTTPS terminator. We’re just gonna go with a simple HTTP server:</p><pre>‘use strict’;</pre><pre>var Primus = require(‘primus’)<br>  , http = require(‘http’);</pre><pre>var server = http.createServer()<br>  , primus = new Primus(server, { transformer: ‘websockets’ });</pre><p>As you can see from the example we need to specify the transformer we want to use. Transformers are the real-time frameworks you wanted use. Now that we’ve created our server we need to listen for incoming real-time connections:</p><pre>primus.on(‘connection’, function (socket) {<br>  socket.on(‘data’, function ping(message) {<br>    console.log(‘recieved a new message’, message);<br>    socket.write({ ping: ‘pong’ });<br>  });<br>});</pre><pre>server.listen(8080); // And listen on the HTTP server.</pre><p>This is all you need to accept an incoming connection, receive data and send a reply. What’s really cool about primus is that it automatically takes care of encoding and decoding your messages. The only thing that’s left to do is build a HTML page and connect to the server.</p><pre>&lt;!doctype html&gt;<br>&lt;html lang=”en”&gt;<br>&lt;head&gt;<br>  &lt;meta charset=”utf-8&quot;&gt;<br>  &lt;title&gt;Primus&lt;/title&gt;<br>  &lt;— The client is automatically served by primus. —&gt;<br>  &lt;script src=”/primus/primus.js”&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;p&gt;<br>    Welcome to Primus example.<br>  &lt;/p&gt;<br>  &lt;script&gt;<br>    var primus = new Primus(‘http://localhost:8080/?query=string’);</pre><pre>   primus.write(‘you can write directly, we will queue it’);<br>   primus.write(‘until the open event is called and flush it’);</pre><pre>    primus.on(‘reconnect’, function () {<br>      console.log(‘primus: reconnect event happend’);<br>    });</pre><pre>    primus.on(‘open’, function () {<br>      console.log(‘primus: connection established’);<br>      primus.write(‘hello world’);<br>    });</pre><pre>    primus.on(‘error’, function (err) {<br>      console.log(‘primus: error event’, err);<br>    });</pre><pre>    primus.on(‘data’, function (data) {<br>      console.log(‘primus: received data’, data);<br>    });</pre><pre>    primus.on(‘end’, function () {<br>      console.log(‘primus: connection closed’);<br>    });<br>  &lt;/script&gt;</pre><p>And that’s basically all you need to create a real-time server which is flexible and doesn’t lock you in to any framework.</p><h4>Primus highlights</h4><ul><li>Primus makes it effortless to switch between real-time frameworks and message encoders/decoders.</li><li>It has a simple low level interface that’s compatible with the Node.js streams so you can pipe data back and forth.</li><li>It fixes inconsistencies and bugs in frameworks where needed. So using a real-time framework through primus will most likely run smoother and better than the original plain framework.</li><li>Has build and working reconnect using randomised exponential backoff.</li><li>Comes with a server-side client as well as front-end client for easy testing.</li></ul><p>Primus is released as an <strong>open source</strong> module with an MIT license. It’s available at <a href="https://github.com/3rd-Eden/primus">https://github.com/3rd-Eden/primus</a> and is well documented.</p><p>It doesn’t matter if you’re building a real-time application or want to build a module on top of a real-time framework, Primus is here to do the heavy lifting and allows you to focus on building your application/module without having to worry about the framework that want to use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22af5c94a922" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-build/build-first-decide-later-22af5c94a922">Build first, decide later</a> was originally published in <a href="https://medium.com/the-build">The build</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>