<?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 Arturo on Medium]]></title>
        <description><![CDATA[Stories by Arturo on Medium]]></description>
        <link>https://medium.com/@dunkelheit?source=rss-c831af937e12------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Arturo on Medium</title>
            <link>https://medium.com/@dunkelheit?source=rss-c831af937e12------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:33:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dunkelheit/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[Your Maps, Your Server: Self-Hosting OpenStreetMap So You Never Depend on Google Again]]></title>
            <link>https://dunkelheit.medium.com/your-maps-your-server-self-hosting-openstreetmap-so-you-never-depend-on-google-again-9796b68c0c3c?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/9796b68c0c3c</guid>
            <category><![CDATA[openstreetmap]]></category>
            <category><![CDATA[home-server]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[self-hosting]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Sun, 19 Apr 2026 17:19:42 GMT</pubDate>
            <atom:updated>2026-04-19T17:19:42.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyf63wmGHKmjKRECG-6wCQ.png" /><figcaption>Yep, that’s how it’s going to eventually look like!</figcaption></figure><p>This is acomplete guide to run a <strong>self-hosted</strong> (runs on your hardware), <strong>offline-capable</strong> (works if Google Maps or Apple Maps go down, or start removing certain streets / areas) <strong>world map</strong> on an Unraid server (or any other Docker-capable system, for that matter) using <strong>TileServer-GL</strong>, <strong>Protomaps vector tiles</strong>, and <strong>MapLibre styles</strong>.</p><p>Because I run Unraid myself, this guideline has been written with Unraid in mind, but I will try to make it as general as possible so that you can also have your own map solution in any system that supports running Dockerized services.</p><h3>What you’ll get</h3><p>Basically, that. A fully self-hosted map service (visually comparable to Google Maps or Apple Maps) running on your Unraid server, or any server where you can run Docker services.</p><p>The map uses OpenStreetMap data rendered as vector tiles with no dependency on the Internet. The entire world map fits in a single ~120 GB file.</p><h3>Architecture overview</h3><p>A self-hosted map using TileServer-GL is a pipeline of four components:</p><ol><li><strong>Tile data: </strong>a Protomaps .pmtiles file containing the entire world&#39;s vector tile data, derived from OpenStreetMap.</li><li><strong>Tile server:</strong> TileServer-GL, which serves those tiles over HTTP and handles server-side raster rendering.</li><li><strong>Map style: </strong>a MapLibre GL style JSON that tells the renderer how to draw roads, buildings, labels, parks, water, etc.</li><li><strong>Assets:</strong> font glyphs (for rendering text labels like street names) and sprites (for icons like landmarks, parks, churches, public transport stops, etc.)</li></ol><p>TileServer-GL bundles all of these into a single Docker container with a built-in web viewer. No separate frontend deployment is needed.</p><h3>Prerequisites</h3><ul><li>An Unraid server with Docker support enabled; or any system capable of running Docker services.</li><li>At least <strong>130 GB of free disk space</strong> for the planet tile data, fonts, sprites, and styles.</li><li>SSH access to the Unraid server for terminal commands.</li><li>Basic familiarity with Docker container management on Unraid.</li><li>Optional: A working reverse proxy setup (Nginx Proxy Manager is assumed throughout this guide).</li></ul><h3>Step 1: Create a share for map data</h3><blockquote>This step is only necessary if you are using Unraid.</blockquote><p>Create a dedicated Unraid share to store the map data. This keeps the large .pmtiles file separate from your appdata share.</p><ol><li>In the Unraid web UI, go to <strong>Shares</strong> → <strong>Add Share</strong>.</li><li>Name the share maps.</li><li>Configure the share settings according to your storage preferences (cache pool vs. array). See the note below.</li></ol><p>The resulting path will be /mnt/user/maps.</p><blockquote><strong><em>Cache vs. array:</em></strong><em> The planet </em><em>.pmtiles file is ~120 GB. If your </em><em>appdata share uses cache-only storage, putting map data there would consume a significant portion of your cache pool. </em><strong><em>If you want the fastest possible first-tile load times, put it on cache; if you want to preserve cache space, put it on the array.</em></strong></blockquote><h3>Step 2: Download the planet tile data</h3><p>Protomaps publishes free, weekly-updated planet builds as .pmtiles files. Each file contains vector tiles for the entire world at zoom levels 0–15 (street-level detail).</p><p>Open a terminal in Unraid, or SSH into your Unraid server, and download the latest build:</p><pre>cd /mnt/user/maps<br><br># Check https://maps.protomaps.com/builds for the latest available date.<br># Replace 20260412 with the most recent build date.<br>wget https://build.protomaps.com/20260412.pmtiles</pre><p>This is a ~120 GB download. Run it inside tmux or screen so it survives SSH disconnections. Worst case scenario, if the download is interrupted, try to resume it with:</p><pre>wget -c https://build.protomaps.com/20260412.pmtiles</pre><h4>Optional: Download only a region</h4><p>If you don’t need the <em>entire world</em>, you can extract a specific region using the pmtiles CLI tool. This significantly reduces download size: a Europe extract is roughly 30–50 GB.</p><pre># Install the pmtiles CLI<br>cd /tmp<br><br># Find the right release for your system in <br># https://github.com/protomaps/go-pmtiles/releases<br>wget https://github.com/protomaps/go-pmtiles/releases/latest/download/go-pmtiles_Linux_x86_64.tar.gz<br><br># Unpack and move to /usr/local/bin (or wherever you want to keep it)<br>tar xzf go-pmtiles_Linux_x86_64.tar.gz<br>mv pmtiles /usr/local/bin/<br>chmod +x /usr/local/bin/<br><br># Dry-run to see the extract size before downloading<br>cd /mnt/user/maps<br>pmtiles extract \<br>  https://build.protomaps.com/20260412.pmtiles \<br>  europe.pmtiles \<br>  --bbox=-25,34,45,72 \<br>  --dry-run<br><br># If the size looks good, drop --dry-run to download<br>pmtiles extract \<br>  https://build.protomaps.com/20260412.pmtiles \<br>  europe.pmtiles \<br>  --bbox=-25,34,45,72</pre><p>The --bbox parameter is west,south,east,north in longitude/latitude. Use <a href="http://bboxfinder.com/">bboxfinder.com</a> to draw a bounding box and copy the coordinates you will see in after the “box” label in the bottom bar, like in the screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCuu_p6VDWzcLX_zf9mngQ.png" /><figcaption>Use the “box” icon to draw a box over the section of the map you would like to run on your own, and check the coordinates on the bottom bar after the label “box”.</figcaption></figure><blockquote><strong><em>Reminder:</em></strong><em> Bounding boxes are rectangles, not country borders. A Europe box will include parts of North Africa, western Russia, and Turkey as side effects.</em></blockquote><h3>Step 3: Install TileServer-GL</h3><h4>Option A: Unraid community applications (recommended)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hu8z77bc4dfD6YLvUs7y2g.png" /></figure><ol><li>In the Unraid web UI, go to <strong>Apps</strong> (Community Applications).</li><li>Search for <strong>TileServer-GL</strong>.</li><li>Install the app. During configuration:<br>- Set the data volume mapping to /mnt/user/maps → /data.<br>- Note the host port number you assign (e.g., 8777).</li><li>Apply and start the container.</li></ol><h4>Option B: Docker Compose (via plugins like “Compose Manager Plus”)</h4><p>If you prefer Docker Compose, create a compose.yml file (I haven’t tested this path myself, though):</p><pre>services:<br>  tileserver-gl:<br>    image: maptiler/tileserver-gl:latest<br>    container_name: TileServer-GL<br>    restart: unless-stopped<br>    ports:<br>      - &quot;8777:8080&quot;<br>    volumes:<br>      - /mnt/user/maps:/data<br>    # Networking is optional, this is just how I configure Docker<br>    # services on my Unraid server so that they belong to multiple<br>    # appropriate networks<br>    networks:<br>      - productivity_network<br>      - proxy_network<br># Just like in the comment above: completely optional if you don&#39;t<br># care about where network(s) the container will belong to.<br>networks:<br>  productivity_network:<br>    external: true<br>  proxy_network:<br>    external: true</pre><p>Deploy via Compose Manager Plus or from the terminal:</p><pre>cd /path/to/your/compose/project<br>docker compose up -d</pre><h4>Verify the container is running</h4><pre>docker ps | grep -i tile</pre><p>You should see the container running. Visit http://&lt;your-server-ip&gt;:&lt;port&gt;/ in your browser, or click on the icon of TileServer-GL and select “WebUI”.</p><p>TileServer-GL&#39;s landing page should appear, but the map won&#39;t look right yet. <strong>That&#39;s expected; we haven&#39;t configured styles or fonts.</strong></p><h3>Step 4: Create the configuration file</h3><p>Create /mnt/user/maps/config.json with the following content:</p><pre>{<br>  &quot;options&quot;: {<br>    &quot;paths&quot;: {<br>      &quot;root&quot;: &quot;/data&quot;,<br>      &quot;fonts&quot;: &quot;fonts&quot;,<br>      &quot;styles&quot;: &quot;styles&quot;,<br>      &quot;sprites&quot;: &quot;sprites&quot;,<br>      &quot;pmtiles&quot;: &quot;&quot;<br>    },<br>    &quot;serveStaticMaps&quot;: true<br>  },<br>  &quot;styles&quot;: {<br>    &quot;protomaps-light&quot;: {<br>      &quot;style&quot;: &quot;protomaps-light.json&quot;<br>    }<br>  },<br>  &quot;data&quot;: {<br>    &quot;planet&quot;: {<br>      &quot;pmtiles&quot;: &quot;20260412.pmtiles&quot;<br>    }<br>  }<br>}</pre><p>Some paths like fonts, styles, sprites don’t exist yet: <strong>don’t worry, we will create them a bit later</strong>.</p><p>Adjust the filename under data.planet.pmtiles to match whatever you downloaded in Step 2 (e.g., europe.pmtiles if you extracted a region).</p><blockquote><strong><em>Tip:</em></strong><em> Consider renaming your </em><em>.pmtiles file to </em><em>planet.pmtiles (or </em><em>europe.pmtiles). Date-stamped filenames mean editing </em><em>config.json every time you download a newer build.</em></blockquote><h3>Step 5: download and install fonts and sprites</h3><p>TileServer-GL needs font glyphs to render text labels (street names, city names, etc.) and sprite assets to render map icons (park markers, public transport stops, landmark symbols). Without fonts, the map renders geometry but all text labels are invisible.</p><h4>Download the Protomaps basemaps assets</h4><pre>cd /tmp<br>wget https://github.com/protomaps/basemaps-assets/archive/refs/heads/main.tar.gz<br>tar xzf main.tar.gz</pre><h4>Install the fonts</h4><pre>mkdir -p /mnt/user/maps/fonts<br>cp -r /tmp/basemaps-assets-main/fonts/* /mnt/user/maps/fonts/</pre><p>After this, /mnt/user/maps/fonts/ should contain subdirectories named after fonts(e.g., Noto Sans Regular, Noto Sans Medium), each containing files like 0-255.pbf, 256-511.pbf, etc. These are pre-rasterized glyph ranges: the renderer fetches only the Unicode ranges it needs for visible labels.</p><h4>Install the sprites</h4><pre>mkdir -p /mnt/user/maps/sprites<br>cp /tmp/basemaps-assets-main/sprites/v4/light.json /mnt/user/maps/sprites/<br>cp /tmp/basemaps-assets-main/sprites/v4/light.png /mnt/user/maps/sprites/<br>cp /tmp/basemaps-assets-main/sprites/v4/light@2x.json /mnt/user/maps/sprites/<br>cp /tmp/basemaps-assets-main/sprites/v4/light@2x.png /mnt/user/maps/sprites/</pre><p>The @2x variants are for high-DPI (Retina) displays. If you plan to use a different style theme (dark, grayscale, etc.), copy those sprite files too.</p><h4>Clean up</h4><pre>rm -rf /tmp/main.tar.gz /tmp/basemaps-assets-main</pre><h3>Step 6: Download and configure the map style</h3><p>The map style is a MapLibre GL JSON file that defines how every map feature is drawn: road colors, building fills, label fonts, zoom-level visibility thresholds, and more. Protomaps publishes ready-made styles designed for their planet tileset.</p><h4>Get the style JSON</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3AQd8p83hw-hj4Xtwb_BQ.png" /><figcaption>You will go to the ProtoMaps website and get the JSON styles you need on your own maps.</figcaption></figure><ol><li>Open <a href="https://maps.protomaps.com/">https://maps.protomaps.com/</a> in your browser.</li><li>Find the <strong>“Get style JSON”</strong> option.</li><li>Select the <strong>light</strong> theme (or whichever theme you prefer — dark, grayscale, white, and black are also available).</li><li>Download the generated JSON file.</li><li>Copy it to /mnt/user/maps/styles/protomaps-light.json on your Unraid server:</li></ol><pre>mkdir -p /mnt/user/maps/styles<br># Copy the downloaded file to:<br># /mnt/user/maps/styles/protomaps-light.json</pre><h4>Edit the Style JSON</h4><p>The downloaded style JSON points at Protomaps’ cloud API by default. <strong>You need to redirect it to your local tile server.</strong> Open the file in a text editor and make three changes.</p><p><strong>Change 1: Point the tile source at your local data.</strong></p><p>Find the sources block (near the top of the file):</p><pre>&quot;sources&quot;: {<br>  &quot;protomaps&quot;: {<br>    &quot;type&quot;: &quot;vector&quot;,<br>    &quot;url&quot;: &quot;https://api.protomaps.com/tiles/v4.json?key=...&quot;<br>  }<br>}</pre><p>Replace it with:</p><pre>&quot;sources&quot;: {<br>  &quot;protomaps&quot;: {<br>    &quot;type&quot;: &quot;vector&quot;,<br>    &quot;url&quot;: &quot;pmtiles://{planet}&quot;<br>  }<br>}</pre><p>The {planet} token references the data source ID from your config.json (the key you used under data). If you named it something else (like europe), use {europe} here instead.</p><blockquote><strong><em>Important:</em></strong><em> The source name </em><em>protomaps must stay the same. Every layer in the style&#39;s </em><em>layers array references this source by name. If you rename it here, you&#39;d need to update every layer definition too.</em></blockquote><p><strong>Change 2: Point fonts at your local glyphs.</strong></p><p>Find the top-level glyphs property:</p><pre>&quot;glyphs&quot;: &quot;https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf&quot;</pre><p>Change it to:</p><pre>&quot;glyphs&quot;: &quot;{fontstack}/{range}.pbf&quot;</pre><p>TileServer-GL resolves this relative path against /data/fonts/ (as configured in config.json&#39;s paths.fonts).</p><p><strong>Change 3: Point sprites at your local copies.</strong></p><p>Find the top-level sprite property:</p><pre>&quot;sprite&quot;: &quot;https://protomaps.github.io/basemaps-assets/sprites/v4/light&quot;</pre><p>Change it to:</p><pre>&quot;sprite&quot;: &quot;light&quot;</pre><p>TileServer-GL resolves this against /data/sprites/ (as configured in config.json&#39;s paths.sprites) and automatically appends .json, .png, @2x.json, and @2x.png.</p><blockquote><strong><em>Common mistake:</em></strong><em> Do NOT set this to </em><em>sprites/light. TileServer-GL already prepends the </em><em>sprites path from your config — setting </em><em>sprites/light here results in the doubled path </em><em>/data/sprites/sprites/light.json, which fails with a file-not-found error.</em></blockquote><h4>Validate the JSON</h4><p>After editing, make sure the file is still valid JSON:</p><pre># Assumes you have python3 installed, feel free to try other approaches<br># like loading the JSON file with a small Node.js script<br>cat /mnt/user/maps/styles/protomaps-light.json | python3 -c &quot;import sys,json; json.load(sys.stdin); print(&#39;Valid JSON&#39;)&quot;</pre><p>If this prints an error, you likely have a missing comma or mismatched bracket from the edits.</p><h3>Step 7: Restart and verify</h3><p>Restart the container and watch the startup logs:</p><pre>docker restart TileServer-GL &amp;&amp; docker logs -f TileServer-GL</pre><p>Ctrl+C to detach from the log stream. No worries, this does not stop the container, just stops tailing the log file.</p><h4>What to Look For in the Logs</h4><p><strong>Good signs:</strong></p><ul><li>Starting tileserver-gl v5.x.x</li><li>Using specified config file from config.json</li><li>Starting server</li><li>Listening at <a href="http://.../">http://...</a></li></ul><p><strong>Warning signs (non-fatal):</strong></p><ul><li>[SECURITY WARNING] Host header poisoning mitigation is NOT enabled: harmless for now, fixed in Step 8.</li></ul><p><strong>Error signs:</strong></p><ul><li>The specified path for &quot;fonts&quot; does not exist (/data/fonts): fonts directory is missing or empty. Go back to Step 5.</li><li>Render error: ... ENOENT ... sprites/sprites/...: doubled sprite path. Check your style JSON&#39;s sprite property (Step 6, Change 3).</li><li>Error: Cannot find module... or container crashes on start: likely an image issue. Verify you&#39;re running maptiler/tileserver-gl:latest (the full image), not tileserver-gl-light.</li></ul><h4>Test in the browser</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be8jvcjqLdN-R3q7GCh5bA.png" /><figcaption>Your maps should look now something like that :)</figcaption></figure><p>Open http://&lt;your-server-ip&gt;:&lt;port&gt;/ in your browser. The TileServer-GL landing page should now show:</p><ul><li>A <strong>Styles</strong> section with protomaps-light listed, including a rendered preview thumbnail.</li><li>A <strong>Data</strong> section with planet listed.</li></ul><p>Click the <strong>Viewer</strong> button next to protomaps-light. You should see a fully rendered world map with:</p><ul><li>Colored roads, buildings, parks, and water</li><li>Text labels for cities, streets, and landmarks at appropriate zoom levels</li><li>Smooth vector zoom (not pixelated raster tiles)</li></ul><p>If the map appears but labels are missing, fonts are not installed correctly. If the map is entirely grey or blank, see the troubleshooting section below.</p><h3>Step 8 (Optional): Set up a reverse proxy (like Nginx Proxy Manager)</h3><h4>Add the environment variable</h4><p>Before configuring NPM, add the TILESERVER_GL_ALLOWED_HOSTS environment variable to the TileServer-GL container. Without it, TileServer-GL may generate internal URLs that browsers can&#39;t reach when accessed through a reverse proxy, resulting in a grey/blank map.</p><p><strong>If using the Unraid Docker UI:</strong></p><ol><li>Go to the <strong>Docker</strong> tab.</li><li>Click the TileServer-GL container icon → <strong>Edit</strong>.</li><li>Add a new environment variable:<br>- <strong>Key:</strong> TILESERVER_GL_ALLOWED_HOSTS<br>- Value: maps.home.local (replace with your own subdomain)</li><li>Apply.</li></ol><p><strong>If using Docker Compose</strong>, add it to the environment block:</p><pre>environment:<br>  - TILESERVER_GL_ALLOWED_HOSTS=maps.home.local</pre><p>Then redeploy with docker compose up -d.</p><h4>Configure NPM</h4><ol><li>In Nginx Proxy Manager, add a new <strong>Proxy Host</strong>.</li><li><strong>Domain Names:</strong> maps.home.local (or your chosen subdomain).</li><li><strong>Scheme:</strong> http</li><li><strong>Forward Hostname / IP:</strong> TileServer-GL (the container name, resolvable over the shared Docker network).</li><li><strong>Forward Port:</strong> 8080 (the container&#39;s internal port, not the host-mapped port).</li><li><strong>Enable WebSockets Support:</strong> Yes (the MapLibre viewer uses WebSocket connections for some interactions).</li><li>Configure SSL as appropriate for your setup (Let’s Encrypt wildcard certificate, etc.).</li></ol><h4>Verify</h4><p>Open https://maps.home.local/ (or your configured domain). The map should load with full styling, labels, and icons. If the map appears grey or blank:</p><ul><li>Open the browser developer console (F12 → <strong>Console</strong> tab) and look for CORS errors or failed network requests.</li><li>Check that TILESERVER_GL_ALLOWED_HOSTS is set correctly — this is the most common cause of grey maps behind a reverse proxy.</li><li>Verify that the container is on the same Docker network as NPM (proxy_network or equivalent).</li></ul><h3>Step 9 (Optional): Add a health check</h3><p>Health checks let Docker monitor whether TileServer-GL is actually serving requests, not just running.</p><h4>If using the Unraid Docker UI:</h4><ol><li>Edit the TileServer-GL container.</li><li>Switch to <strong>Advanced View</strong> (toggle in the upper right).</li><li>In the <strong>Extra Parameters</strong> field, add:</li></ol><pre>--health-cmd=&quot;wget --spider -q http://localhost:8080/health || exit 1&quot; --health-interval=30s --health-timeout=5s --health-retries=3 --health-start-period=30s</pre><p>Apply the changes.</p><h4><strong>If using </strong>Docker<strong> Compose</strong></h4><p>Add to the service definition:</p><pre>healthcheck:<br>  test: [&quot;CMD&quot;, &quot;wget&quot;, &quot;--spider&quot;, &quot;-q&quot;, &quot;http://localhost:8080/health&quot;]<br>  interval: 30s<br>  timeout: 5s<br>  retries: 3<br>  start_period: 30s</pre><p>After applying, docker ps should show (healthy) next to the container after about 30 seconds.</p><blockquote><strong><em>Note:</em></strong><em> The health check uses port </em><em>8080 (the container&#39;s internal port), not whatever host port you mapped. If </em><em>wget is not available in the image, substitute with </em><em>curl -fsS http://localhost:8080/health || exit 1.</em></blockquote><h3>File layout reference</h3><p>After completing all steps, your /mnt/user/maps directory should look like this:</p><pre>/mnt/user/maps/<br>├── 20260412.pmtiles          # Planet tile data (~120 GB)<br>├── config.json               # TileServer-GL configuration<br>├── fonts/                    # Font glyphs for text rendering<br>│   ├── Noto Sans Bold/<br>│   │   ├── 0-255.pbf<br>│   │   ├── 256-511.pbf<br>│   │   └── ...<br>│   ├── Noto Sans Regular/<br>│   │   ├── 0-255.pbf<br>│   │   ├── 256-511.pbf<br>│   │   └── ...<br>│   └── ... (other font stacks)<br>├── sprites/                  # Map icons<br>│   ├── light.json<br>│   ├── light.png<br>│   ├── light@2x.json<br>│   └── light@2x.png<br>└── styles/                   # MapLibre style definitions<br>    └── protomaps-light.json</pre><h4>Updating the map data</h4><p>The .pmtiles file is a read-only archive. To update it with fresher OpenStreetMap data:</p><ul><li>Check <a href="https://maps.protomaps.com/builds">https://maps.protomaps.com/builds</a> for the latest available build date.</li><li>Download the new file:</li></ul><pre>cd /mnt/user/maps<br>wget https://build.protomaps.com/YYYYMMDD.pmtiles -O 20260412.pmtiles.new</pre><ul><li>Swap the files atomically:</li></ul><pre>mv 20260412.pmtiles.new 20260412.pmtiles</pre><ul><li>Restart the container:</li></ul><pre>docker restart TileServer-GL</pre><p>The map data is typically a few weeks behind real-world changes due to OSM processing and build schedules. For most use cases, updating monthly or even less frequently is more than sufficient.</p><h3>Troubleshooting</h3><h4>Map is entirely grey or blank (behind reverse proxy)</h4><p><strong>Cause:</strong> TileServer-GL is generating internal URLs (like http://tileserver-gl:8080/...) that the browser can&#39;t reach.</p><p><strong>Fix:</strong> Set the TILESERVER_GL_ALLOWED_HOSTS environment variable to your public domain name. See Step 8.</p><h4>Map renders geometry but no text labels</h4><p><strong>Cause:</strong> Font glyphs are missing. TileServer-GL can’t render text without pre-rasterized font files.</p><p><strong>Fix:</strong> Install fonts as described in Step 5. Check the startup logs for The specified path for &quot;fonts&quot; does not exist.</p><h4>Render error: ENOENT sprites/sprites/…</h4><p><strong>Cause:</strong> The sprite property in your style JSON already includes the sprites/ prefix, and TileServer-GL is prepending the paths.sprites config on top of it, resulting in a doubled path.</p><p><strong>Fix:</strong> In your style JSON, change &quot;sprite&quot;: &quot;sprites/light&quot; to &quot;sprite&quot;: &quot;light&quot;. See Step 6, Change 3.</p><h4>Style preview thumbnail is blank on the landing page</h4><p><strong>Cause:</strong> Server-side raster rendering failed, usually due to the sprite path issue above.</p><p><strong>Fix:</strong> Fix the sprite path first. The thumbnail is rendered live by the server using MapLibre GL Native. Once the style loads correctly, the thumbnail renders automatically.</p><h4>The .pmtiles file is on a spun-down array disk</h4><p><strong>Expected behavior:</strong> The first map tile request after the disk has spun down will take a few extra seconds while the disk spins up. Subsequent requests will be faster. This is normal Unraid behavior and does not indicate a problem.</p><h3>What this guide does not cover</h3><ul><li><strong>Geocoding (address search):</strong> Requires a separate service like Nominatim or Photon. Nominatim needs 1.3–1.6 TB of PostGIS storage for a full planet import. Photon is lighter (~80 GB) but still a significant deployment. Neither is required for map viewing.</li><li><strong>Routing (directions from A to B):</strong> Requires a separate service like Valhalla, OSRM, or GraphHopper, each with its own preprocessed planet graph.</li><li><strong>Custom map styles:</strong> The Protomaps light theme used in this guide is one of several available themes. Advanced users can write custom MapLibre GL styles or modify existing ones. See the <a href="https://maplibre.org/maplibre-style-spec/">MapLibre Style Specification</a> for documentation.</li><li><strong>Multiple style themes:</strong> You can serve multiple styles simultaneously by adding more entries to the styles block in config.json and downloading additional style JSONs and sprite sets for each theme.</li></ul><h3>Problems? Do let me know!</h3><p>I wrote this article after I successfully installed TileServer-GL on my own Unraid server, so there’s a chance I overlooked something or made the wrong copy paste from the terminal history.</p><p>If something doesn’t add up, make sure to drop a comment!</p><h3>References</h3><ul><li><a href="https://tileserver.readthedocs.io/">TileServer-GL Documentation</a></li><li><a href="https://github.com/maptiler/tileserver-gl">TileServer-GL GitHub Repository</a></li><li><a href="https://docs.protomaps.com/">Protomaps Documentation</a></li><li><a href="https://maps.protomaps.com/builds">Protomaps Planet Builds</a></li><li><a href="https://github.com/protomaps/basemaps-assets">Protomaps Basemaps Assets (fonts, sprites)</a></li><li><a href="https://github.com/protomaps/basemaps">Protomaps Basemaps (styles, tile generation)</a></li><li><a href="https://github.com/protomaps/PMTiles">PMTiles Specification</a></li><li><a href="https://maplibre.org/maplibre-gl-js/docs/">MapLibre GL JS</a></li><li><a href="https://maplibre.org/maplibre-style-spec/">MapLibre Style Specification</a></li><li><a href="https://www.openstreetmap.org/">OpenStreetMap</a></li><li><a href="http://bboxfinder.com/">bboxfinder.com (bounding box tool)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9796b68c0c3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Goodbye Netflix! Building my own home streaming and media server with Unraid and the *arr apps]]></title>
            <link>https://dunkelheit.medium.com/goodbye-netflix-building-my-own-home-streaming-and-media-server-with-unraid-and-the-arr-apps-cabceb764049?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/cabceb764049</guid>
            <category><![CDATA[home-server]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[unraid]]></category>
            <category><![CDATA[plex]]></category>
            <category><![CDATA[usenet]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Sat, 04 Oct 2025 17:55:56 GMT</pubDate>
            <atom:updated>2025-10-04T18:11:44.766Z</atom:updated>
            <content:encoded><![CDATA[<p>Half year ago I decided to move away from streaming services like Netflix, Apple TV and HBO Max. Shows I loved being removed or censored, content fragmentation, price hikes, and general enshittification were the main reasons behind this stampede.</p><p>Now I run my own home streaming and media server. A couple of friends have witnessed this solution in real life and have asked me to share the details; which is not an easy task, because this journey took many evenings of reading, tinkering, breaking things and starting over from scratch.</p><p>In this series of articles I will share all my learnings in setting up such a streaming and media server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4NkHH1Qvd5vxOsew" /><figcaption>Photo by <a href="https://unsplash.com/@oscnord?utm_source=medium&amp;utm_medium=referral">Oscar Nord</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Ingredients</h3><h4>The hardware</h4><ul><li><strong>A television.</strong> Obviously! The specifications of your television will have an impact on some choices down the line, for example: whether it can display 1080p or 4K content; whether it supports Dolby Vision (DV), or HDR10+, or HDR.</li><li><strong>A computer.</strong> That computer will be your home media server. Content will be stored here and get streamed to the television. Furthermore, a number of applications will be running in this server so that we can find, fetch and organize all our media.</li><li>Optionally, a <strong>streaming media player</strong> like <a href="https://www.nvidia.com/en-us/shield/shield-tv-pro/">NVIDIA SHIELD TV Pro</a>. I chose to get it because both its hardware and its media player client were more powerful than my TV’s. The Shield’s Plex app is faster, more stable, and supports a wider range of formats. It can <strong>direct-play high-bitrate 4K, Dolby Vision, and Dolby Atmos</strong> without server-side transcoding, and its powerful Tegra X1+ chip handles decoding locally, preserving both quality and CPU power on the server.</li><li><strong>Wired ethernet connection</strong> between all the physical components (television, computer, streaming media player, and wireless router), to enjoy the highest possible bandwidth while streaming media.</li></ul><p>The goal of this ecosystem is to be able to have Plex do <strong>Direct Play</strong> of content from the home server into the television. <strong>Direct Play</strong> means that the video and audio are already in a format my device (the NVIDIA SHIELD TV Pro) can handle, so Plex simply sends the file <strong>as-is</strong>. This preserves the original quality and uses almost no CPU on the server, because the server won’t have to <strong>transcode</strong> (i.e. converting a video or audio file from one format to another in real time<strong>) </strong>the content into a format supported by the receiving device.</p><h4>The subscriptions</h4><p>Yeah, here’s the thing. You will still need some subscriptions; but at this point it’s costing me less money than having several streaming services.</p><ul><li>A <strong>Usenet provider</strong>, which gives you access to the Usenet network. In my case, I’m using <a href="https://www.eweka.nl/en">Eweka</a>.</li><li>One or more <strong>Usenet indexers</strong>, which are the “search engines” for Usenet content. Some of them provide lifetime access with one single reasonably priced payment, but monthly/yearly subscriptions are quite cheap. In my case, I’m using <a href="https://drunkenslug.com/">DrunkenSlug</a>, <a href="https://abnzb.com/">abNZB</a>, <a href="https://althub.co.za/">altHUB</a>, <a href="https://nzb.su/">Nzb.su</a>, <a href="https://nzbfinder.ws/">NZBFinder</a>, <a href="https://www.google.com/search?client=safari&amp;rls=en&amp;q=NZBGeek&amp;ie=UTF-8&amp;oe=UTF-8">NZBGeek</a> and <a href="https://nzbplanet.net/">NzbPlanet</a>.</li></ul><h4>The software</h4><ul><li>The “direct replacement” of Netflix et al will be <a href="http://plex.tv/"><strong>Plex</strong></a>. It has a separate client (for the TV or the streaming media player) and server (for the computer) applications.</li><li>A bunch of applications running as <strong>Docker services</strong> in the computer. More about them later. This ecosystem of services will be working together, talking to each other, delegating responsibilities, etc., to guarantee that whatever (new) content I request is available to stream in Plex in a matter of minutes. A lot of these applications belong to the <strong>*Arr stack</strong>: a family of open-source, self-hosted applications that automate the downloading, management, and organization of media like movies, TV shows, music, and more.</li></ul><h4>Documentation and guides</h4><p>All you need to fine-tune the configuration of all the services in your home server can be found in the famous <a href="http://trash-guides.info/">Trash Guides</a>. You <strong>DO NOT</strong> need to follow these guides blindly; more about that later.</p><h3>Deep dive in the software stack</h3><p>The main applications we will be using are as follows:</p><ul><li><a href="https://unraid.net/"><strong>Unraid</strong></a><strong>:</strong> The operating system of our home server. Delivers parity-protected storage, Docker container management, and easy virtualization. All through an intuitive web interface.</li><li><strong>Plex Media Server</strong>: The heart of your personal streaming platform. It organizes your movies, shows, and music with rich metadata and streams them to all your devices, locally or remotely.</li><li><strong>Plex Media Client</strong>: The app you use to watch content; whether on your TV, phone, or browser. It connects to your Plex Media Server, offering a Netflix-like interface with your own content.</li><li><a href="https://radarr.video/"><strong>Radarr</strong></a><strong>:</strong> Automates movie management. It monitors your wanted list, grabs new releases from Usenet or torrents, and adds them to your library, fully renamed and organized, and in the quality you’ve configured them to be.</li><li><a href="https://sonarr.tv/"><strong>Sonarr</strong></a><strong>:</strong> Like Radarr, but for TV shows. It tracks upcoming episodes, handles season packs, and keeps your series collection complete and consistent.</li><li><a href="https://prowlarr.com/"><strong>Prowlarr</strong></a><strong>:</strong> A unified Usenet indexer manager. It connects Radarr, Sonarr, and other apps to multiple Usenet and torrent indexers, syncing searches and API keys in one place.</li><li><a href="https://sabnzbd.org/"><strong>SABnzbd</strong></a><strong>:</strong> A lightweight Usenet downloader. It receives NZB files from Prowlarr and downloads, repairs, and extracts them automatically.</li><li><a href="https://deluge-torrent.org/"><strong>Deluge</strong></a>: A flexible torrent client often used alongside SABnzbd for content that’s easier to find on public or private trackers.</li></ul><p>Optional services:</p><ul><li><a href="https://overseerr.dev/"><strong>Overseerr</strong></a><strong>:</strong> A beautiful web app for managing requests from other household members. My girlfriend can browse my catalog, request new movies or shows, and get automatic updates when they’re available.</li><li><a href="https://www.bazarr.media/"><strong>Bazarr</strong></a><strong>:</strong> Handles subtitles for your entire library. It automatically downloads and syncs multilingual subtitles for new and existing media.</li><li><a href="https://github.com/recyclarr/recyclarr"><strong>Recyclarr</strong></a><strong>:</strong> Keeps Radarr and Sonarr configurations clean and consistent. It syncs your quality profiles and custom formats with the community-maintained Trash Guides.</li><li><a href="https://github.com/FlareSolverr/FlareSolverr"><strong>Flaresolverr</strong></a><strong>:</strong> A helper service that bypasses Cloudflare and other anti-bot protections, allowing Prowlarr (and apps depending on it) to access protected indexer sites smoothly.</li></ul><h3>Deep dive in the hardware</h3><p>I chose the following components to build my home server.</p><ul><li><strong>Case: Fractal Design Node 304 Mini-ITX</strong><br>In my case, the first and foremost limiting factor in my build was the space where the computer would sit. This case fits perfectly in the shelves next to the TV, and has a very decent airflow.</li><li><strong>CPU: Intel Core i5–13500 + Noctua NH-L12S</strong><br>Low consumption and powerful enough to transcode 4K content if necessary.</li><li><strong>Board: B760I AORUS PRO DDR4</strong><br>Decent ITX board with 4 SATA ports for 4 hard disks. Won’t be enough to fill the entire case, but for that we will use a separate expansion card.</li><li><strong>Memory: 64 GB Corsair LPX DDR4–3200</strong><br>Because we will be running quite some Docker applications. And because we will be keeping the transcoded media chunks in memory rather than in the disks. In 99% of the cases the media will be streamed as Direct Play, but I want to leave enough room for when transcoding is necessary.</li><li><strong>Drives: 2x Kingston KC3000 2TB M.2 NVME and 6x WD Red Pro 16 TB 3.5&quot;</strong><br>The m.2 disks will implement what in Unraid is called the “cache pool” (configuration and Docker images), and the 3.5&quot; ones will contain the actual media, in what Unraid calls the “array pool”. One of the 3.5&quot; hard disks will be the parity disk that will save my ass in case something goes wrong with the others, which leaves me with a total of <em>80 TB</em> of available disk space for content.</li><li><strong>Fans: NF-A14 PWM 140mm (exhaust) and Noctua NF-A9 PWM 92 mm (intake)</strong><br>It’s important to keep the inside of the computer cool.</li><li><strong>PSU: Corsair SF750</strong></li><li><strong>Controller: LSI SAS2308 HBA</strong><br>Our motherboard only has 4 SATA ports, but we have 6 hard disks. This professional card will expand the amount of SATA ports available. I found one in eBay, and then attached a small fan (Noctua NF-A4x20-FLX) to its heatsink to keep lower temperatures inside the case.</li></ul><h3>What happens once you get all the ingredients?</h3><p>Boy oh boy, where to begin? There are many small things here and there. Like I said in the introduction, it’s taken me weeks of learning, tinkering and finetuning to get to this point.</p><p>For this first article, let’s start with a simple walkthrough of what happens behind the scene from the moment I decide I want to watch something unavailable in my home server, until the moment it’s ready to be watched.</p><h4>What happens behind the scenes: a spoiler</h4><p>Let’s imagine that there is some content that I want to watch. This content does not reside yet inside my home streaming server, so it needs to be somehow found, fetched, organized and made available for Plex to stream.</p><p>What does this journey look like?</p><ol><li><em>Option a)</em> I will search for a movie in <strong>Radarr</strong>, or a TV show in <strong>Sonarr</strong>. They have access to a vast <em>catalogue</em> of content; but that’s just that: a <em>catalogue</em>, a <em>database</em>, something like IMDb. They don’t “have it” per se — they just know it exists. In any case, they will find it in their catalogue, and I will tell Radarr (or Sonnar) to <strong>go get it</strong>. But not just “go get whatever”: I will specify the quality that I want for that specific content: it could be Blu-ray 1080p quality, or maybe 4K Dolby Vision, or maybe just plain DVD quality because it’s a very, very old TV show. What I have specified in my search is called a “<strong>Quality Profile</strong>” in the world of Sonarr and Radarr.<br><em>Option b)</em> My girlfriend will find a TV show or movie she liks in Overseerr and file a request to download it. The request will be approved automatically by Overseerr because I love her so very much.</li><li><strong>Radarr / Sonarr</strong> will perform a search for this content through <strong>Prowlarr</strong>. They will search for it in all the configured Usenet indexers. Eventually, they will find <em>the best version of that content according to my wishes</em>. This it a very important detail; to reiterate: in the previous step I have specified which one of my configured “quality profiles” I want the content to be in. So Radarr / Sonarr will give <strong>scores</strong> to each search result and pick up the instance with the <strong>highest score</strong>.</li><li><strong>Prowlarr</strong> will instruct <strong>SABnzbd</strong> to fetch the content from Usenet. The content will be downloaded in the M.2 SSD disks (Unraid’s “cache pool”.)</li><li>Once the content is downloaded, <strong>SABnzbd</strong> will “unpack” it and sanitize, a bit of post-processing. The content is now downloaded <em>and</em> ready to be picked up by <strong>Sonarr / Radarr</strong>.</li><li><strong>Sonarr / Radarr</strong> has been monitoring the download and now realizes it’s time to deal with the downloaded content. The first thing it will do is <em>moving</em> the content from the M.2 SSD disk (“cache pool”) into the 3.5&quot; hard disks (“array pool”). As part of this moving, the content will be <strong>placed in the right directory</strong>, and will be <strong>renamed in configured and standardized way</strong> that <strong>Plex Media Server</strong> can easily identify what kind of TV show or movie it is, so it can properly fetch all its metadata (poster, description, cast, etc.)</li><li>Once the content has been moved to the right place, Sonarr / Radarr will ping <strong>Plex Media Server</strong> to make sure that it is immediately incorporated into the right library (Movies, TV shows, anime, etc.), and then it can start fetching the content’s metadata (poster, etc.)</li><li>At this point, the content is available in the <strong>Plex Media Client</strong> and I can watch it on my TV.</li><li><strong>Plex Media Server</strong> will also ping <strong>Overseerr</strong> in case it was my girlfriend the one who requested it, so that <strong>Overseerr</strong> can send a message to our home <strong>Telegram</strong> group to let her know she can start watching the new content.</li><li>In parallel, <strong>Bazarr</strong> is already searching for English and Spanish subtitles (in case the content didn’t ship with those already). If they are found, they will be downloaded and stored next to the content files.</li></ol><p>In the next articles of this series I will go into details like:</p><ul><li>Configuring Unraid.</li><li>How the Docker services actually communicate with each other.</li><li>Directory structure in the hard disk pools.</li><li>Quality profiles and scores.</li><li>Automating everything as much as possible.</li></ul><p>Do you have any questions at this point? Do you know something that I don’t? Please let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cabceb764049" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When should you use sinon’s restore and reset functions?]]></title>
            <link>https://javascript.plainenglish.io/when-should-you-use-sinons-restore-and-reset-functions-bdbd39550a2f?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdbd39550a2f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[sinon]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 10:30:10 GMT</pubDate>
            <atom:updated>2021-10-20T08:50:59.504Z</atom:updated>
            <content:encoded><![CDATA[<h3>When Should You Use sinon’s Restore and Reset Functions?</h3><h4>In this article we analyze differences of the restore, reset, resetHistory and resetBehaviour functions in sinon, and how they behave depending on whether our sinon fakes are anonymous or they wrap existing properties.</h4><p>A very common approach while working with sinon, as <a href="https://sinonjs.org/releases/latest/sandbox/">shown in their own documentation</a>, is to call the function restore as part of Mocha’s afterEach hook.</p><pre>afterEach(function () {<br>    // completely restore all fakes created through the sandbox<br>    sandbox.restore();<br>});</pre><p>This should be enough to make sure everything is back to normal when a new test starts, and they don’t influence each other, right? Well, <strong>this is sometimes not the case</strong>.</p><p>Let’s have a look at the following example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89ac61cbecbb768611491d61d4fcbe52/href">https://medium.com/media/89ac61cbecbb768611491d61d4fcbe52/href</a></iframe><p>Looks like restore did its job fine, except for the call count of the log.info spy. We were expecting to have it called just <strong>once</strong> as part of the second unit test, but it turns out the call count from the previous unit test was not properly reset, and the value of the spy’s callCount is <strong>3</strong>.</p><h3>Why doesn’t sinon.restore work as I expected?</h3><p>If we look at the documentation of the restore function of a sinon spy, we will read the following:</p><blockquote>Replaces the spy with the original method.<strong> Only available if the spy replaced an existing method</strong>.</blockquote><p>The highlighted sentence is the key. The restore functions in sinon <strong>only work on spies and stubs that replace an existing method</strong>, and our spy was created as an anonymous (standalone) spy.</p><p>Therefore, restore does not reset the call count, which will continue increasing as the spy function is called in subsequent tests.</p><p>How can we make it work?</p><h3>Introducing the reset and resetHistory functions</h3><p>If we look at the documentation, we will find that spies and stubs have some of the following functions:</p><ul><li>resetHistory: for <strong>spies</strong>, it resets the state; for <strong>stubs</strong>, it resets the history call. For <strong>sandboxes</strong>, it resets the history of all stubs created in the sandbox.</li><li>resetBehavior: only available for <strong>stubs</strong> and <strong>sandboxes</strong>, it resets the stub’s original behavior.</li><li>reset: for <strong>stubs</strong>, resets both behavior and history; for <strong>sandboxes</strong>, resets the internal states of everything created in the sandbox.</li></ul><p>In our example, we can use the resetHistory function to make sure the call count of the spy gets reset after the first test, so that its execution doesn’t conflict with the second test. We can do this as part of Mocha’s afterEach hook:</p><pre>afterEach(() =&gt; {<br>    sandbox.restore();<br><strong>    log.info.resetHistory();</strong><br>});</pre><p>Bear in mind: adding sandbox.reset() in the afterEach hook will not help, but it works if we add it to the end of the first unit test — still haven’t figured out why this is happening.</p><h3>Or just avoid using anonymous spies</h3><p>That would be another option. Instead of using anonymous spies:</p><pre>const log = {<br>    info: sandbox.spy(),<br>    error: sandbox.spy()<br>};</pre><p>Have a generic log mock object and mount the spies on it:</p><pre>const log = {<br>    info: function () { /* Do nothing */ },<br>    error: function () { /* Do nothing */ }<br>};</pre><pre>sandbox.spy(log, &#39;info&#39;);<br>sandbox.spy(log, &#39;error&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XkpTPK1N3SpPBhmN" /><figcaption>Photo by <a href="https://unsplash.com/@bernardhermant?utm_source=medium&amp;utm_medium=referral">Bernard Hermant</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdbd39550a2f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/when-should-you-use-sinons-restore-and-reset-functions-bdbd39550a2f">When should you use sinon’s restore and reset functions?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make Keycloak Start Up Faster When There Are a Lot of Offline Sessions]]></title>
            <link>https://medium.com/swlh/how-to-make-keycloak-start-up-faster-when-there-are-a-lot-of-offline-sessions-78ee49a907cb?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ee49a907cb</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Sat, 21 Nov 2020 19:32:26 GMT</pubDate>
            <atom:updated>2020-11-22T20:39:11.767Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have offline sessions enabled in Keycloak and there are lots of them stored in the database (e.g. more than 300k) you will notice that the time it takes to start up can be up to more than 20 minutes. In this article I will share some tips we implemented to make it go faster. In our case,<strong> we managed to start up with 750k offline sessions in 2 only minutes 58 seconds</strong>, instead of ~15 minutes!</p><p>I will also explain <strong>how to programmatically change the value of the property </strong><strong>sessionsPerSegment</strong>, both in the XML configuration and using the JBoss CLI, which is crucial to improve the startup times.</p><p>This issue has already been reported in the following JIRA tickets:</p><ul><li><a href="https://issues.redhat.com/browse/KEYCLOAK-11019">KEYCLOAK-11019</a>: Offline sessions preloading still slow in some cases</li><li><a href="https://issues.redhat.com/browse/KEYCLOAK-7275">KEYCLOAK-7275</a>: Pre-loading offline sessions from DB can timeout in slow environments (DefaultExecutorService timeout)</li></ul><p>The first step is increasing the property sessionsPerSegment from the default 10 to a value around 512.</p><h3>Setting sessionsPerSegment to 512</h3><p>This property seems to determine the amount of offline sessions that will be loaded up in every “batch”; at least that’s my understanding from debug level logs during startup.</p><h4>Option 1: in the standalone(-ha).xml configuration</h4><p>Simply add the following to your standalone(-ha).xml configuration file. You can place it next to the other &lt;spi&gt; nodes.</p><pre>&lt;spi name=&quot;userSessions&quot;&gt;<br>    &lt;provider name=&quot;infinispan&quot; enabled=&quot;true&quot;&gt;<br>        &lt;properties&gt;<br>            &lt;property name=&quot;sessionsPerSegment&quot;<br>                      value=&quot;${env.SESSIONS_PER_SEGMENT:512}&quot; /&gt;<br>        &lt;/properties&gt;<br>    &lt;/provider&gt;<br>&lt;/spi&gt;</pre><p>The reason we set the value to ${env.SESSIONS_PER_SEGMENT:512} is so that we can override our (new) default value of 512 using the environment variable SESSIONS_PER_SEGMENT.</p><h4>Option 2: programmatically, using the JBoss CLI</h4><p>Although I recommend setting the variable using the XML configuration, it is also possible to programmatically set it using the JBoss CLI.</p><p>The approach will depend on whether the property sessionsPerSegment exists (because it was set in the configuration file) or not.</p><p>If the property was already never set before:</p><ol><li>Open a terminal to your Keycloak instance and go to the folder where the binaries reside. In case you are using an official Docker image, it will be /opt/jboss/keycloak/bin.</li><li>Run the script ./jboss-cli</li><li>Connect to Keycloak using the command connect.</li><li>Add the userSessions SPI with: /subsystem=keycloak-server/spi=userSessions:add()</li><li>Add the infinispan provider to the userSessions SPI: /subsystem=keycloak-server/spi=userSessions/provider=infinispan:add(enabled=true)</li><li>Set the property: /subsystem=keycloak-server/spi=userSessions/provider=infinispan:write-attribute(name=properties.sessionsPerSegment,value=512)</li><li>Reload with reload</li></ol><p><strong>In case the property already existed before, you can skip steps 4 and 5.</strong></p><p>The output should look something similar to this:</p><pre>// Add the userSessions SPI<br>[standalone@localhost:9990 /] /subsystem=keycloak-server/spi=userSessions:add()<br>{&quot;outcome&quot; =&gt; &quot;success&quot;}</pre><pre>// Add the infinispan provider to the userSessions SPI<br>[standalone@localhost:9990 /] /subsystem=keycloak-server/spi=userSessions/provider=infinispan:add(enabled=true)<br>{&quot;outcome&quot; =&gt; &quot;success&quot;}</pre><pre>// Now you can add the property :)<br>[standalone@localhost:9990 /] /subsystem=keycloak-server/spi=userSessions/provider=infinispan:write-attribute(name=properties.sessionsPerSegment,value=512)<br>{<br>    &quot;outcome&quot; =&gt; &quot;success&quot;,<br>    &quot;response-headers&quot; =&gt; {<br>        &quot;operation-requires-reload&quot; =&gt; true,<br>        &quot;process-state&quot; =&gt; &quot;reload-required&quot;<br>    }<br>}</pre><pre>// Reload!<br>[standalone@localhost:9990 /] reload</pre><h3>Add extra indices to the database</h3><p>The JIRA issues mentioned in the beginning of this article mention that adding some extra indices might be helpful to speed up startup times. Maybe because we were not using the version 11 of PostgreSQL, which comes with some optimizations for queries to use indices in IN clauses, we did not see much of an improvement. But they might be worth adding nevertheless.</p><p>On the table offline_user_session, add an index on the columns user_session_id, created_on and offline_flag:</p><pre>CREATE INDEX offline_user_session_user_session_id_idx ON public.offline_user_session USING btree (user_session_id, created_on, offline_flag)</pre><p>Just in case, on the table offline_client_session, add an index on the columns user_session_id, timestamp and offline_flag:</p><pre>CREATE INDEX offline_client_session_user_session_id_idx ON public.offline_client_session USING btree (user_session_id, &quot;timestamp&quot;, offline_flag)</pre><h3>Upgrade to PostgreSQL version 11</h3><p>It was briefly hinted in the previous section, but it is recommended to use at least the version 11 of Postgres, since it comes with an optimization on IN clauses to use indices.</p><h3>Our startup speed improvement</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kCxiktFqAh0IJWO_" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">CHUTTERSNAP</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We went from ~15 minutes startup time to just 2 minutes and 58 seconds, without using PostgreSQL version 11 <em>and</em> without having the extra indices.</p><p>Hopefully these tips will help you as well!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ee49a907cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-to-make-keycloak-start-up-faster-when-there-are-a-lot-of-offline-sessions-78ee49a907cb">How to Make Keycloak Start Up Faster When There Are a Lot of Offline Sessions</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The dangers of deep equal assertions in Chai.js]]></title>
            <link>https://javascript.plainenglish.io/the-dangers-of-deep-equal-assertions-in-chai-js-f25a212f671f?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25a212f671f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 11:46:54 GMT</pubDate>
            <atom:updated>2020-10-29T16:25:06.929Z</atom:updated>
            <content:encoded><![CDATA[<h4>Deep equal assertions are faster to implement but usually come with a dangerous lack of attention</h4><p>Has anyone in your team ever said something like this? “<em>It was covered by unit tests, but we were comparing it against the wrong value!”</em></p><p>Most of the times I’ve heard that, there was a deep equal assertion involved. <strong>Deep equal assertions in Chai.js are extremely simple and fast to implement</strong> — why write assertions property by property when I can just do a deep comparison of an object that I can easily copy-paste in my tests? —<strong> but by doing so, developers miss the chance to ask themselves: is the value of this property what it <em>really</em> should be?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KPj1bk0_VJjihgKwfND_3Q.png" /></figure><p>Consider a person object that results from a transformation function with some business logic inside it. Let’s imagine that the property isActive is determined by some internal checks in that function.</p><p>Often, a developer will just debug or console.log the contents of the person object and happily throw them into a deep.equal comparison, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaa53a851290e3d7d59894b534c4f25d/href">https://medium.com/media/aaa53a851290e3d7d59894b534c4f25d/href</a></iframe><p><em>“My unit test is passing, all is good!”</em></p><p>Unfortunately, the developer did not spend any time to <em>really</em> think about every single one of the properties in the object. It turns out isActive should have been true, and by the time someone in the team realizes the mistake, the damage will already be done.</p><p>Note to self, and to you all: <strong>don’t be lazy</strong>. Take some extra time to <strong>really, really think about every assertion</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5c6b5837656e04c1d11b392234d33e7/href">https://medium.com/media/b5c6b5837656e04c1d11b392234d33e7/href</a></iframe><h3>When does Chai.js perform deep equal comparisons?</h3><p>There are two ways in which Chai.js will do such comparisons:</p><ul><li>expect(o1).to.<strong>eql</strong>(o2): asserts that <em>o1</em> is deeply equal to <em>o2</em> using <a href="https://github.com/chaijs/deep-eql">their own deep equality algorithm</a>. Has the alias eqls.</li><li>expect(o1).to.<strong>deep.equal</strong>(o2): same as before, with one very important difference. This causes deep equality comparisons to also be used for any other assertions that follow in the chain.</li></ul><p><strong>Invest in good unit tests, you will sleep better at night!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25a212f671f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-dangers-of-deep-equal-assertions-in-chai-js-f25a212f671f">The dangers of deep equal assertions in Chai.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When is it okay to Unit Test private variables and functions in JavaScript?]]></title>
            <link>https://javascript.plainenglish.io/unit-testing-private-variables-and-functions-in-javascript-when-is-it-ok-6090bd43c7b5?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/6090bd43c7b5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 16:06:02 GMT</pubDate>
            <atom:updated>2020-10-26T17:11:11.976Z</atom:updated>
            <content:encoded><![CDATA[<h4>Asking this question might be a sign of underlying design flaws. And the first step to fix them.</h4><h4>Why you usually shouldn’t test them</h4><p>In her book <a href="https://www.poodr.com/"><em>Practical Object Oriented Design in Ruby</em></a>, Sandi Metz enumerates the following reasons <strong>not</strong> to include private methods in unit tests:</p><ul><li><strong>Redundancy</strong>: private methods are hidden inside public components that <em>already</em> have tests; a failure in them will always be exposed by an existing test.</li><li><strong>Instability</strong>: private methods are more likely to change, and when they do, so will the tests. This costs time.</li><li><strong>Exposure</strong>: testing private methods exposes them to a bigger audience who might be misled into using them, therefore breaking encapsulation by depending on them.</li></ul><p>I can say I only wholeheartedly agree with the first point: redundancy. And despite being valid points, they are more suited for actual object oriented programming, an aspect where JavaScript is not quite there yet.</p><p>There is another excerpt from the book that I find more compelling with regards to not testing private variables or methods:</p><p><strong>[Unit tests] expose design flaws in the underlying code.</strong> If a test requires painful setup, the code expects too much context. If testing one object drags a bunch of others into the mix, the code has too many dependencies. If the test is hard to write, other objects will find the code difficult to reuse.</p><p>This bit made me reconsider the way I was approaching unit testing in the last JavaScript package that I published. We will look into that now.</p><h4>…and how to test them anyways</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jFw-BMU32WutMYiH" /><figcaption>Photo by <a href="https://unsplash.com/@austriannationallibrary?utm_source=medium&amp;utm_medium=referral">Austrian National Library</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Consider the following simplified snippet from my JavaScript module <a href="https://www.npmjs.com/package/pending-promise-recycler">pending-promise-recycler</a>:</p><pre>const registry = new <strong><em>Map</em></strong>();</pre><pre>module.exports = function recycle(func, options = {}) {<br>    // Here, we use the variable <strong>registry</strong> to cache promises.<br>    // The <strong>key</strong> of the cached function comes from the <strong>options</strong> and the<br>    // developer can either use a custom function or rely on a       <br>    // default builder that uses function name and arguments.<br>    // If the cache is a <strong>hit</strong>, return the cached function<br>    // If it&#39;s a <strong>miss</strong>, cache the function and return it<br>});</pre><p>For the implementation of a number of unit tests, I thought the easiest way would be to have access to the registry variable, which is not exposed by the module. This can be easily achieved using the module <a href="https://www.npmjs.com/package/rewire"><strong>rewire</strong></a>:</p><pre>const rewire = require(&#39;rewire&#39;);</pre><pre>const recycle = rewire(&#39;./index&#39;);</pre><pre>const registry = <strong>recycle.__get__(&#39;registry&#39;)</strong>;</pre><p>For more details, check the <a href="https://github.com/Dunkelheit/pending-promise-recycler/blob/main/index.test.js">full unit test suite</a>.</p><p>Good! Now I can test, among others, the following three cases:</p><ol><li>The functions cached in the registry have keys which can either be built by a custom function, or determined by the function name and a has of its arguments.</li><li>The registry is emptied after (promise) functions no longer belong in there because they have been resolved, preventing potential memory leaks.</li><li>The cache actually works, there are hits and misses depending on whether a function is still in the cache registry or not.</li></ol><p>But, wait… do I really need to access the private variable registry for this? Time to go back to my favorite excerpt from the book. It became clear that, after crossing the checks for easy setup and execution, I was not looking at the unit tests from the right angle. <strong>A failure in the private variable </strong><strong>registry should be detectable by the superficial, public behavior of the function</strong>.</p><ul><li><strong>For the test 1 and 3</strong>, and without going much into implementation details, I can easily create a unit test to verify that a function that is already in the cache will not be executed twice by using a <a href="https://sinonjs.org/releases/latest/spies/">sinon spy</a> to assert that the cached function has not been called twice, but once. This should be applicable to both custom or default key building functions, as described in the case 1.</li><li><strong>For the case 2</strong>, I can verify that functions get eventually removed from the cache because once they are fulfilled, any next call to the cached function will not be a hit but a miss. This can also be easily tested using a sinon spy.</li></ul><p>Unit testing private variables is really tempting and, in JavaScript, extremely easy thanks to modules like rewire. <strong>If you find yourself having to make assertions over private variables, it might be the indicator that either your implementation or your approach to unit testing deserve some more time and attention</strong>.</p><p>In the end, let common sense decide!</p><p>Have you faced similar situations? I’d love to hear how it went! Drop me a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6090bd43c7b5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/unit-testing-private-variables-and-functions-in-javascript-when-is-it-ok-6090bd43c7b5">When is it okay to Unit Test private variables and functions in JavaScript?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Increasing promise performance with pending-promise-recycler]]></title>
            <link>https://javascript.plainenglish.io/increasing-promise-performance-with-pending-promise-recycler-52fe6e65d545?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/52fe6e65d545</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 14:45:41 GMT</pubDate>
            <atom:updated>2020-10-24T15:08:35.408Z</atom:updated>
            <content:encoded><![CDATA[<h4>The fastest promise in JavaScript is the one that has already been resolved!</h4><p>The npm package <a href="http://npmjs.com/package/pending-promise-recycler">pending-promise-recycler</a> keeps track of promises in a pending state; that means ongoing promises that have not been resolved yet.</p><p>If someone would try to create a new instance of one of those pending promises, pending-promise-recycler will <strong>reuse</strong> the one that is currently pending <strong>instead of unnecessarily creating a duplicate one</strong>.</p><h3>How to use pending-promise-recycler?</h3><p>Simply wrap any function that returns a promise with pending-promise-recycler:</p><pre>const <strong>recycle</strong> = require(&#39;pending-promise-recycler&#39;);</pre><pre>const func = () =&gt; { return Promise.resolve(); }<br>const <em>recycledFunc</em> = <strong>recycle</strong>(func);</pre><pre><em>recycledFunc</em>().then(...);</pre><p><strong>Any extra call to </strong><strong>recycledFunc while it is still pending will not incur in an extra call to </strong><strong>func</strong>; instead, the pending promise will be recycled and used again in any subsequent call.</p><h3>A practical example with an express app</h3><p>Let’s have a look at a more realistic example. The following code snippet shows a simple express server with an endpoint that calls a very slow and expensive function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4848f80ffd50226f306f8b49951e358e/href">https://medium.com/media/4848f80ffd50226f306f8b49951e358e/href</a></iframe><p>If we call this endpoint, the function someSlowAndExpensiveOperation will be called once.</p><pre>🍕 node index.js &amp;<br>[1] 81740<br>Express server up and running!</pre><pre>✦ 🍕 curl <a href="http://localhost:3000/">http://localhost:3000/</a><br>Starting a very slow operation!<br>Slow operation is over!<br>{&quot;foo&quot;:&quot;bar&quot;}<br>Request: 1517.251ms</pre><p>But if we fire 10,000 calls at the same time, we will be calling someSlowAndExpensiveOperation 10,000 times too! Even if we would cache the first response from the operation, we would still be calling func 10,000 times because the cached response isn’t there yet by the time the second request arrives!</p><h4>Improving our express app with pending-promise-recycler</h4><p>What would happen if we would recycle someSlowAndExpensiveOperation? Let’s look at the following, improved version of our express app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4848f80ffd50226f306f8b49951e358e/href">https://medium.com/media/4848f80ffd50226f306f8b49951e358e/href</a></iframe><p>We are now recycling the slow and expensive operation.</p><p>If we use apache-bench to make 5 concurrent requests to our app…</p><pre>🍕 ab -n 5 -c 5 -k <a href="http://localhost:3000/">http://localhost:3000/</a></pre><p>Our app logs will look like this:</p><pre>&gt;&gt;&gt; Incoming request<br><strong>Starting a very slow operation!</strong><br>&gt;&gt;&gt; Incoming request<br>&gt;&gt;&gt; Incoming request<br>&gt;&gt;&gt; Incoming request<br>&gt;&gt;&gt; Incoming request<br><strong>Slow operation is over!</strong><br>&lt;&lt;&lt; Outgoing response<br>&lt;&lt;&lt; Outgoing response<br>&lt;&lt;&lt; Outgoing response<br>&lt;&lt;&lt; Outgoing response<br>&lt;&lt;&lt; Outgoing response</pre><p><strong>We responded to all these concurrent requests with one single resolution of the promise in the function </strong><strong>someSlowAndExpensiveOperation</strong> , instead of redundantly calling this function 5 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKRsevrzzD9rxL-I9lJFkA.png" /></figure><p>The module pending-promise-recycler is available in <a href="https://www.npmjs.com/package/pending-promise-recycler">npm</a> and <a href="https://www.npmjs.com/package/pending-promise-recycler">GitHub</a>.</p><p>Contributions and issue reports are more than welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52fe6e65d545" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/increasing-promise-performance-with-pending-promise-recycler-52fe6e65d545">Increasing promise performance with pending-promise-recycler</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Would You Use POST Instead of GET for a Read Operation?]]></title>
            <link>https://medium.com/swlh/why-would-you-use-post-instead-of-get-for-a-read-operation-381e4bdf3b9a?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/381e4bdf3b9a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Sun, 18 Oct 2020 14:23:32 GMT</pubDate>
            <atom:updated>2020-10-18T18:50:01.531Z</atom:updated>
            <content:encoded><![CDATA[<h4>Exploring scenarios in which we might want to deviate from the standard.</h4><p>Normally, I’d say “no, you don’t”; because GET is for read operations and POST is meant for write (e.g. create) operations.</p><p>But today I was reading the draft of some OpenAPI specifications, in which one of our REST API consumers suggested having a new endpoint to look up users by their phone number. And they wanted this to be a POST endpoint. So I asked myself: <em>why would they want this?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Xumf6_Uv2nxjLOtP9PtqQ.png" /></figure><h3>Security reasons</h3><p>When a get GET request is received, many servers log information about the incoming request. Most of them will log the whole requested URL including query parameters, which might include sensitive information. In our case, we would be potentially logging the phone number of our users.</p><p>Let’s see if we can verify this claim. We will spin up a dockerized NGINX…</p><pre>&gt; docker run -it --rm -d -p 8080:80 --name web nginx</pre><p>…and see what happens when we try to access http://localhost:8080/user/1234567890 (assuming 1234567890 to be the user’s phone number.)</p><pre>172.17.0.1 - - [18/Oct/2020:13:46:35 +0000] &quot;GET / HTTP/1.1&quot; 200 612 &quot;-&quot; &quot;Mozilla/5.0 (***) ***&quot; &quot;-&quot;<br>2020/10/18 13:46:46 [error] 28#28: *1 open() &quot;/usr/share/nginx/html/user/123456789&quot; failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: &quot;GET /user/123456789 HTTP/1.1&quot;, host: &quot;localhost:8080&quot;</pre><p>Even thought it returned a 404 error, we can see that the whole URL path gets logged. Even the first request to /, which was successful, logs the whole path. If this system would be hacked, logs could be retrieved and phone number information could potentially be exposed and leaked.</p><h3>URL length</h3><p>Browsers and HTTP servers can have a maximum URL length. For example Microsoft Internet Explorer is limited to 2,048 characters, and Apache HTTP Server can handle up to 4,000 characters in a URL. In our case, given that a telephone number might have a maximum length of 9 characters, there would be no reason to use POST instead of GET.</p><h3>Accountability</h3><p>There is a very interesting point in the W3C’s paper <a href="https://www.w3.org/2001/tag/doc/whenToUseGet.html">URIs, Addressability, and the use of HTTP GET and POST</a>:</p><blockquote>Use POST if […] (the) user <strong>be held accountable for the results of the interaction</strong>.</blockquote><p>Requesting a user’s profile exposes an individual’s personally identifiable information. One could argue that requesting this data should not be done lightly.</p><p>But isn’t this a semantic decision, just as much as the decision of using GET for because it is a <em>read</em> operation?</p><p>In the end, common sense and reason should prevail. Even if it goes against the REST principles, if one doesn’t want to risk PII like phone numbers to be logged, then go ahead and use POST instead of GET.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=381e4bdf3b9a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/why-would-you-use-post-instead-of-get-for-a-read-operation-381e4bdf3b9a">Why Would You Use POST Instead of GET for a Read Operation?</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recycling Pending Promises in Node.js]]></title>
            <link>https://medium.com/swlh/recycling-pending-promises-in-node-js-958fe562e94d?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/958fe562e94d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[promises]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Sat, 17 Oct 2020 12:07:27 GMT</pubDate>
            <atom:updated>2020-10-17T20:16:17.211Z</atom:updated>
            <content:encoded><![CDATA[<h4>With the package “pending-promise-recycler”, we can save precious resources and avoid performing the same operation again and again by recycling pending promises.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Eniw02nSX--iGiJ8" /><figcaption>Photo by <a href="https://unsplash.com/@javedo?utm_source=medium&amp;utm_medium=referral">Javier Huedo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine the following scenario.</p><p>We have an API that sometimes makes calls to a 3rd party service; for example, to retrieve a list of stores. Let’s assume that retrieving this list of stores is a very expensive and slow operation, averaging a response time of about 12 seconds.</p><p>As soon as we get the response, we probably want to cache it somehow so that we don’t make our API consumers wait for so long every time they need to get a list of stores.</p><p>But what would happen when 1,000 of our API consumers fire a call to our store list endpoint <em>at the same time</em>?</p><ul><li>The first request comes in. It realizes there isn’t a store list in the cache yet, so it fires the call. Just to remind you, this call will take around 12 seconds.</li><li>The second request comes it one millisecond later. There is still no store list in the cache, so it fires another call. This will take another 12 seconds.</li><li>The other 998 requests will come in, not finding anything in the cache. Another 998 calls will be fired.</li><li>There will be 1,000 operations to save the store list in the cache, 999 of them being completely unnecessary.</li><li>All the 1,000 requests will take around 12 seconds to respond.</li><li>The 3rd party API that provides us with a store list will probably not very happy about our hammering of their service.</li></ul><p><strong>Wouldn’t it be nice if our API would somehow be aware that there is an ongoing, pending promise to a list of stores created by the first request, and all the other 999 requests would be fulfilled with that same single promise?</strong></p><h3>Introducing pending-promise-recycler</h3><p>To facilitate the recycling of pending promises I’ve written the Node.js module <a href="https://www.npmjs.com/package/pending-promise-recycler">pending-promise-recycler</a>.</p><p>Let’s imagine we have an API like the one described before, and a very slow or expensive operation similar to the one to retrieve a list of stores:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfba2b304780214cb98555f0f4089c26/href">https://medium.com/media/cfba2b304780214cb98555f0f4089c26/href</a></iframe><p>With pending-promise-recycler, we can “wrap” our fetchSomethingExpensive function to make it aware of any other pending version of itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4445445b842d22675dd7d15ddcdda14/href">https://medium.com/media/f4445445b842d22675dd7d15ddcdda14/href</a></iframe><p>In this example with four concurrent executions of recyclableFetch(), our very expensive fetchSomethingExpensive function <strong>gets only executed and resolved once, but satisfies all the four executions</strong>.</p><h3>How does it work?</h3><p>The module pending-promise-recycler keeps track of all ongoing, pending promises using a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">Map</a>.</p><pre>const registry = new <strong><em>Map</em></strong>();</pre><p>We need to somehow identify each possible function that might be wrapped. By default, they will be individually identified by their function name and a concatenation of their arguments. Of course, this might work for simple functions and systems, but ideally we will define our own identified by either using a string or a function — the behavior of which can be found in a <a href="https://github.com/Dunkelheit/pending-promise-recycler#identifying-recyclable-promises">separate section in the documentation</a>.</p><pre>const identifier = typeof options.keyBuilder === &#39;function&#39;<br>    ? options.keyBuilder(func, ...args) : options.keyBuilder;</pre><p>We will check if there is a pending promise for the given function in the registry. If there is one, we will return it.</p><pre>if (registry.has(identifier)) {<br>    return registry.get(identifier);<br>}</pre><p>If there is no pending promise in the registry, we will start the execution of the function and store it in the registry.</p><pre>const res = func(...args);<br>registry.set(identifier, res);</pre><p>We will wait for it to resolve (or be rejected!) and then we will remove it from the registry and return its result.</p><pre>try {<br>    await res;<br>} finally {<br>    registry.delete(identifier);<br>}<br>return res;</pre><p>pending-promise-recycler can be found in <a href="https://www.npmjs.com/package/pending-promise-recycler">npm</a> and <a href="https://github.com/Dunkelheit/pending-promise-recycler">GitHub</a>. Issues and pull requests are more than welcome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=958fe562e94d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/recycling-pending-promises-in-node-js-958fe562e94d">Recycling Pending Promises in Node.js</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Documentation for Forgetful Programmers]]></title>
            <link>https://medium.com/icemobile/continuous-documentation-for-programmers-with-poor-memory-118e8022e78b?source=rss-c831af937e12------2</link>
            <guid isPermaLink="false">https://medium.com/p/118e8022e78b</guid>
            <category><![CDATA[work]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Arturo]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 10:43:46 GMT</pubDate>
            <atom:updated>2020-09-08T13:54:34.147Z</atom:updated>
            <content:encoded><![CDATA[<h4>And non-programmers too!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q2s6AekELHnkMxuT" /><figcaption>Photo by <a href="https://unsplash.com/@lauracathleen?utm_source=medium&amp;utm_medium=referral">Laura Fuhrman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’ve always considered my work-related memory to be subpar.</p><p>I would often be asked whether I remember how we implemented X or why we chose option Y; and even though we did implement X and chose option Y three or four times, the answer would forever remain hiding on the tip of my tongue and never show up. This here is a terrible feeling that would make me feel really incompetent.</p><p>One might retort: “Well, why didn’t you write down those oh-so-important things somewhere?”</p><p>I did. But I eventually forgot where. And the answers would change their hiding place from the tip of my tongue to some drawer swamped with papers and post-its or a text file amongst dozens of text files in my hard disk.</p><p>And one day, my mentor told me about <strong>continuous documentation</strong>.</p><h3>Step one: write things down</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pl7Ld7vwaqpTYhMo" /><figcaption>Photo by <a href="https://unsplash.com/@kylejglenn?utm_source=medium&amp;utm_medium=referral">Kyle Glenn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Just start by focusing on just <strong>writing things down</strong>.</p><p>When something remarkable happens, <strong>write it down</strong>.</p><p>When something makes you happy, or upset; <strong>write it down</strong>.</p><p>Any disturbance in your general sense of flow at work: <strong>write it down</strong>.</p><p>As someone who tries to be organized, this is the moment when I would start overthinking how to write things down: “I need to find the right tool”. “I need to define a clear convention”. “I need to come up with a set of categories and labels”. “But do I need labels, or is it just enough with categories?”</p><p><strong>Stop right there</strong>. It doesn’t matter. It can be just a simple text file for now. Let’s park the “making it look professional” for later. For now, just open whatever writing tool you feel comfortable with, and start writing those entries down.</p><p>Don’t worry about anything else now; that’s something for later! Don‘t worry if some entries are short and others are half a page long!</p><pre>* We shouldn&#39;t be deploying to production on a Friday afternoon.</pre><p>☝️ Yeah, that’s a nice one!</p><pre>- *MAYBE IMPORTANT* [my-nodejs-backend-api] [unit-tests] I keep seeing random disconnection errors from the knex library on the OpenShift test environment. It doesn&#39;t seem to cause any issues, but it&#39;s been happening for weeks already and probably some developer should have a look at it. It never seems to happen when running the service locally with docker-compose. Is there a way to consistently reproduce this issue?</pre><p>☝️ Also good!</p><pre>* I think Toby is the Scranton strangler.</pre><p>☝️ Everybody knew it!</p><p>Focus on writing. The most important part comes in the next two steps.</p><h3>Step two: meditate on your notes</h3><p>At the end of the day, we will spend 5 minutes reviewing our daily notes. Make sure you mark yourself as “busy” on your work calendar and Slack, we do not want to be disturbed.</p><p>There might be some realizations here and there. Maybe an entry you wrote in the morning reached closure somewhere in the afternoon, and you have to amend it. You might feel like adding a final entry on today’s log with a general evaluation of how the day went. Maybe you will notice an entry that did not feel so important at the moment of writing, but changed the course of the day for good (or bad.) It could also be time to tidy up a bit the structure of your notes, if you feel up to it.</p><p>That’s good for now; time to go home!</p><h3>Step three: find patterns</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W6744WI7ZwkxNvW8" /><figcaption>Photo by <a href="https://unsplash.com/@markuswinkler?utm_source=medium&amp;utm_medium=referral">Markus Winkler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Every one or two weeks we are going to have a more thorough review of our notes. Make sure you put on your detective hat, because we are going to be looking for patterns.</p><p>Do you remember those times that something really annoying happens in the middle of a very stressful period, and you have to park it because there are more urgent matters to attend to? It’s easy to forget those annoying things once you feel the relief of having solved those urgent matters. This complication will probably happen again, probably during another stressful period. It will be likely forgotten again. This cycle might repeat dozens of times before one realizes it’s time to tackle that little annoyance.</p><p>That is an one example of the type of patterns we will be looking for. Pay close attention and try to find out recurring themes in your notes. It will be helpful if by the end of this session you have written down a nice summary of your findings. This will be a very valuable outcome of the continuous documentation process; treasure it and decide how to address them.</p><h3>Time to get more organized?</h3><p>I started writing my notes in a markdown file. One markdown file per month of the year (e.g. 2016–04.md). Like I mentioned before, in the beginning it was hard to resist the temptation of coming up with a proper standard of writing notes, or finding some fancy tool to organize them. Several years down the line, I’m still writing my markdown files and haven’t had the need to come up with anything fancier than that.</p><p>Some colleagues of mine use <a href="https://bear.app/">Bear</a>, others who prefer digital handwriting use <a href="https://www.goodnotes.com/">GoodNotes</a>.</p><h3>How did this work for me?</h3><p>I started this article sharing my concerns about my poor memory. How did continuous documentation help me improve it?</p><p>In retrospective:</p><ul><li>Writing my notes and mindfully reviewing them <em>daily</em> and <em>again every two weeks</em> helped my memories “sink down better” in my brain. Substantially.</li><li>In case I forgot something in particular, even the simplest editing tool has search functionalities!</li></ul><h3>Continuous documentation tl;dr</h3><ol><li>Write things down.</li><li>Meditate on your notes for 5 minutes at the end of the day.</li><li>Review your notes every one or two weeks and try to find patterns.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=118e8022e78b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/icemobile/continuous-documentation-for-programmers-with-poor-memory-118e8022e78b">Continuous Documentation for Forgetful Programmers</a> was originally published in <a href="https://medium.com/icemobile">IceMobile</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>