<?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[NiceDay Development - Medium]]></title>
        <description><![CDATA[NiceDay Development Blog - Medium]]></description>
        <link>https://medium.com/niceday-dev?source=rss----33a6ea5ab6ed---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>NiceDay Development - Medium</title>
            <link>https://medium.com/niceday-dev?source=rss----33a6ea5ab6ed---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:50:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/niceday-dev" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Minimal Downtime Database Migration from MariaDB Galera Cluster to CloudSQL for MySQL at Production…]]></title>
            <link>https://medium.com/niceday-dev/minimal-downtime-database-migration-from-mariadb-galera-cluster-to-cloudsql-for-mysql-at-production-4eb472e6774a?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/4eb472e6774a</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Ridwan Fajar]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 07:49:16 GMT</pubDate>
            <atom:updated>2022-07-09T07:13:26.695Z</atom:updated>
            <content:encoded><![CDATA[<h3>Minimal Downtime Database Migration from MariaDB Galera Cluster to CloudSQL for MySQL at Production —An Overview to Google Cloud Database Migration Service</h3><h3>Overview</h3><p>Database migration is not an easy task while keep the infrastructure stable and less risky. It might led to some critical risks such as downtime for services or data loss during the migration. By using minimal downtime migration, we could reduce downtime risk to our service into very minimum time. Also by using kind of replication technique, we could prevent data loss from our database.</p><p>Therefore, there is a tool called Database Migration Service from Google Cloud Platform (GCP) that could help us to minimize downtime and data loss risk during the database migration. I will try to explain the concept of minimal downtime database migration by using GCP Database Migration Service based on our real database migration in production from MariaDB Galera Cluster to CloudSQL for MySQL.</p><p>Let’s go to the next section.</p><h3>A. Objectives and motivations</h3><p>There are some objectives behind this migration. First, we want to have resilient and secure MySQL database setup for our chat service. Second, we want infrastructure team to have more time on building a better platform for NiceDay developers.</p><p>Since we are going to let Google Cloud team manage our production databases, we could focus on another aspects such as building automation for our operational tasks, automation to fasten development cycle, maintain site reliability for our NiceDay services and many more.</p><p>Beside the objective, we also have some motivations that led us to perform this migration such as:</p><ul><li><strong>Maintainability</strong>,<strong> </strong>CloudSQL offer some features to support the objective such as auto-resize disk, high availability node, replica node, managed security patch, update OS easily, etc</li><li><strong>Get rid of outdated software</strong>,<strong> </strong>our MariaDB distribution which are currently running is an outdated software. Also for the Ubuntu16.04 which host the database. So, it is better to rebuilding the database with the new version of MySQL or MariaDB and latest OS version rather than keep our outdated software for long term</li><li><strong>Interoperability</strong>,<strong> </strong>moving to CloudSQL help us to achieve higher interoperability. That means when we want to move to another cloud such as AWS or Azure, we could migrate the database easily by using their database migration service</li><li><strong>Easier integration with other GCP services</strong>, CloudSQL are well integrated with other GCP services . So it could level up our cloud infrastructure in GCP.</li></ul><h3>B. Existing chat database setup</h3><p>Our MariaDB Galera cluster is self-hosted database by Infrastructure Team and hosted at Google Cloud Platform. You can see the overview in the below diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbX3tZrhmcIYRYyecylVhA.png" /><figcaption>High level diagram for chat database setup at NiceDay Cloud Infrastructure</figcaption></figure><p>There were three services which pointing to MariaDB. They were Backend, Chat and Airflow. Chat service is Ejabberd server. The service perform read and write operation. Backend and Airflow are perform read operation only.</p><p>We are using MariaDB Galera Cluster which consists of three nodes as master-master replication. MariaDB version is 10.1.0 (released at November 2018) which is equivalent to MySQL 5.7.0 at the time this article written. All Galera nodes run under Ubuntu 16.04 which has already outdated.</p><p>The main thing that challenge us to perform zero downtime database migration is the number of chat records. Total size of exported chat database is more than 50 GB per June 2022. Total rows in <strong>archive</strong> table is almost 48 million rows of chat (markers, last seen, chat messages, etc.).</p><h3>C. Migration option</h3><p>Before we jump to the actual migration, we compare some options such as lift-and-shift migration and Database Migration Service. Both of them are possible to performed. Let’s take a look into detail for each options.</p><h4>C.1. Lift and shift migration</h4><p>As it is name it is just lift the old database and move to the new destination. We only need to perform database export then import the exported database into new destination. Really simple and straightforward. We conducted research to two different approach of lift-and-shift migration. Here we go!</p><p><strong>C.1.1. MySQL CLI</strong></p><p>By performing this operation, we only need to export database from source then import the database to new destination. Unfortunately, this approach required downtime for Backend and Chat service. <strong>The downtime took less than 4 hours </strong>in Production-Testing environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*fRlfjzcbUvSa1JcrAYJquA.png" /><figcaption>lift-and-shift migration by using mysqldump and mysql-cli</figcaption></figure><p>It’s too bad and might consume all error budget in our SLA for Backend and Chat service downtime. So, we didn’t choose this approach.</p><p><strong>C.1.2. CloudSQL Import Tools</strong></p><p>It’s similar to previous option. But it has additional step that should send the backup file to Cloud Storage. Then CloudSQL Import Tools perform database import by reading the backup file from CloudSQL. Unfortunately, this approach also required downtime for Backend and Chat service. Moreover,<strong> the downtime took less than 5 hours </strong>in Production-Testing environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*kDwxeBPuaTSxQTGxdCUoeg.png" /><figcaption>lift-and-shift migration by using mysqldump and CloudSQL Import Tools</figcaption></figure><p>It’s more bad than previous option. So, we didn’t choose this approach.</p><h4>C.2. Database migration service</h4><p>Luckily, GCP offer a good service for migrating database with minimal downtime approach. We were interesting to use this service. But unfortunately, MariaDB currently is not supported yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*1MdqbRarm-2-gWSSt0WuKA.png" /><figcaption>List of supported source databases for GCP Database Migration Service</figcaption></figure><p><a href="https://cloud.google.com/database-migration/docs/mysql/migration-src-and-dest">Supported source and destination databases | Database Migration Service | Google Cloud</a></p><p>Basically, we assume MariaDB could be a source for Database Migration Service. But it isn’t and really unfortunate. If we could use this service, zero downtime database migration is possible 100%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*QqiHrywr4xaEWYHzTFdqAA.png" /><figcaption>Assuming that Database Migration Service worked for MariaDB. But it isn’t.</figcaption></figure><p>We want to achieve zero downtime for database migration. So without stopping the traffic (except switchover), our database could be synced from MariaDB Galera Cluster to CloudSQL in real time. But how it is possible if GCP doesn’t support it officially?</p><p>During the discussion with infrastructure team internally, we found <strong>an experimental idea</strong> to add MySQL as intermediary between MariaDB source to Database Migration Service. Check the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*2Wfe0VAAqTtkvRWN6r-sJg.png" /><figcaption>Adding MySQL chain replica between MariaDB source and Database Migration Service</figcaption></figure><p>MariaDB support slave replication to MySQL officialy, that’s the point that really help us. But how MySQL slave node could be a source for Database Migration Service?</p><p>The answer is by performing chain replica. So within the slave node, we enable it as master node in the same place. By using this approach, Database Migration Service is able to read the MySQL chain replica node as if it’s master source. Finally, we’ve found this applicable in Production-Testing environment.</p><p>How about the implementation in the Production environment? Let’s go to the next section.</p><h3>D. Switchover step by step — an illustration</h3><p>Technically, we choose Database Migration Service as our possible solution to perform zero downtime database migration for our MariaDB Galera Cluster to CloudSQL MySQL.</p><p>We performed the switchover outside SLA hours which exactly took at 09.30 AM GMT+7 until 10.00 AM GMT+7 (Jakarta Local Time) at Sunday, 12th June 2022. Our SLA hours is 09.00 AM GMT+7 until 11.00 PM GMT+7 (Jakarta Local Time + Central European Time) from Monday to Friday. So it would be safer to perform the switchover during weekend.</p><h4>D.1.1 Preparing the migration</h4><p>Before the switchover, we have prepared the database migration by deploying Database Migration Service at Friday, 10th June 2022. The longest part of database migration itself is preparing the chain replication. We have to enable:</p><ul><li>standard master node in on of our MariaDB Galera nodes</li><li>deploy new VM with MySQL 5.7.0 installed on it</li><li>connecting the MySQL node as slave to the MariaDB node</li><li>enable master node inside MySQL slave node to become chain replica node</li><li>deploy Database Migration Service by using MySQL chain replica as as ource database</li><li>let the Database Migration Service performing CDC operation to the CloudSQL replica node</li></ul><p>It’s a quite tough preparation. But we are happy to see this was really work. The chat messages from MariaDB synced to CloudSQL replica node. That is indicating that the Database Migration Service has worked and by using chain replication has became a possible solution even if it’s bit experimental.</p><p>When Database Migration Service perform synchronization for the first time, we didn’t see any downtime there for Backend and Chat service. We could assume that the database migration was <strong>zero downtime</strong>. Even there was a lag during the synchronization, CloudSQL replica node was able to catch up with latest changes from MariaDB node. It’s really cool!</p><p>How about the switchover itself? let’s move to the next section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_eLVcA1JNAcwxPiBb4iHQ.png" /><figcaption>Step 1 — Deploy Database Migration Service</figcaption></figure><h4>D.1.2 Switchover for Backend and Chat service</h4><p>We performed the switchover at Sunday, 12 June 2022 from 09.30 AM GMT+7 until around 10.00 AM GMT+7. Before we jump to stop related services, we checked our daily load testing results which finished two hours before the switchover schedule. Usually, we compare the load testing result before and after major changes to our cloud infrastructure.</p><p>We stopped traffic from Backend and Chat service. Also stopping Airflow from performing many DAGs within it. We ensured there was no incoming traffic to all MariaDB nodes by using netstat command and show processlist SQL query. We also check a bit whether the CloudSQL replica node is ready to be promoted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNSVtAbdfL-tgJVihO3rRg.png" /><figcaption>Step 2 — Start switchover by stopping related services</figcaption></figure><p>Then, we promoted CloudSQL replica node to become master node from Database Migration Service console page. We were waiting until it finished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99iZKyOaJJLtQ9re05dJFA.png" /><figcaption>Step 3 — Promote CloudSQL replica node to become master node</figcaption></figure><p>Finally, promote master task finished. Database Migration Service stopped replication from source database. CloudSQL MySQL master node became an independent instance and ready for incoming traffics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66Jzrbb2Vt2Z0jFHKxsjfQ.png" /><figcaption>Step 4 — Ensure that the CloudSQL become master node</figcaption></figure><p>Last step of this switchover was change IP Address for chat database from MariaDB node IP address to CloudSQL MySQL master node IP address. We changed the IP address through database proxy service and no need for rewriting the codebase or redeploy the service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6DM4c3fHmB37NURKPAAaew.png" /><figcaption>Step 5 — Switchover chat database IP Address at Backend and Chat service to use CloudSQL Master Node IP Address</figcaption></figure><p>During the switchover, Backend service was experiencing <strong>downtime for 8 minutes</strong>. Chat service was experiencing <strong>downtime for 12 minutes</strong>. It’s still better than both services should experience downtime for more than 4 hours if we choose lift-and-shift migration.</p><h4>D.1.3 Enabling high availability</h4><p>To make the CloudSQL MySQL highly available, we enabled standby node in different zone. Just in case there is an outage in current zone (europe-west4-a), the standby node could be triggered by fail over mechanism as GCP mentioned in the CloudSQL documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vb1zw4CCDqJ_PxojvBew1A.png" /><figcaption>Step 7 — Enable high availability for CloudSQL MySQL</figcaption></figure><p>We enabled this feature still on Sunday, 12th June 2022. Unfortunately, there was additional downtime for Backend service when enabling HA feature. Chat service wasn’t affected at all.</p><h4>D.1.4 Add replica node</h4><p>We added replica node to separate loads from production services and ETL services. Airflow have some scheduled DAGs. Those DAGs are quite intensive operation and might block production services (Backend and Chat).</p><p>The replica node is also useful if data team or external researcher want to explore chat database without interrupting the production services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmVOxzfDQS20IyVXQF5_bg.png" /><figcaption>Step 8 — add new replica node for CloudSQL MySQL</figcaption></figure><p>We added this replica at Sunday, 12th June 2022. Backend and Chat service weren’t affected by this step.</p><h4>D.1.5 Switchover for Airflow</h4><p>Finally, Airflow was the last service that get switchover. Airflow now pointing replica node of new chat database. So it won’t interrupt the master node from Backend or Chat service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkV1g3OJXQsAPb0QovadDw.png" /><figcaption>Step 9 — Airflow switchover from old MariaDB to new CloudSQL for MySQL</figcaption></figure><p>The downtime took 24 hours, because we need to perform some validations with data team in the Monday. The migration itself was performed at Sunday morning Jakarta Local Time (GMT+7) and it was outside our office hours. But the downtime is acceptable because existing ETL tasks are not streaming operation.</p><p>After we fixed some issues, Airflow has back at Monday, 13 June 2022.</p><h3>E. Summary</h3><p>Finally, we have migrated our chat database to CloudSQL for MySQL successfully. By using Database Migration Service, the database migration duration is totally 0 ms.</p><p>During switchover, it still took around <strong>12 minutes</strong>. Also there was some additional downtime for <strong>5 minutes</strong> for Backend service when enabling HA feature. Again, It is still better than by using lift-and-shift strategy which might take 4–5 hours.</p><p>After the switchover, we performed load testing to the new setup. We saw that there was no different result when comparing before and after using CloudSQL MySQL.</p><p>The final architecture is described as in below diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZREXXsApNB4U5Pyu4gqHxg.png" /></figure><p>For high availability, we enabled HA feature in CloudSQL. To separate workload request from Airflow, we configure Airflow to read replica node only. Then, master node will be only read and write by chat and backend service.</p><p>There is also room for improvement such as:</p><ul><li>Read operation might be load balanced between master or replica node.</li><li>Finding another <strong>better switchover technique that minimize downtime</strong></li></ul><p>How about the actual implementation? I will create another post that cover the detail of the migration implementation. See you soon.</p><h3>References</h3><ul><li><a href="https://cloud.google.com/database-migration/docs/mysql/quickstart">GCP Database Migration Service Quickstart</a></li><li><a href="https://mariadb.com/kb/en/using-mariadb-replication-with-mariadb-galera-cluster-using-mariadb-replica/#configuring-a-cluster-node-as-a-replication-master">Using MariaDB Replication with MariaDB Galera Cluster</a></li><li><a href="https://hpmtechinc.com/daisy-chain-mysql-replication/">7 Steps to Setup Daisy Chain Replication of MySQL 5.1 to 5.7 to 8.0</a></li><li><a href="https://serverfault.com/questions/332339/way-to-avoid-server-downtime-when-creating-master-slave-relationship/332354#332354">How to get last log position from MySQL Master Node</a></li></ul><blockquote>Special thanks to Ricky (Team Lead) and William from Infrastructure Team who helped me a lot while in discussion to make this migration possible. And they were also helping me during the switchover at the weekend. They are really nice guys.</blockquote><blockquote>Also thanks to stakeholders at NiceDay such as Umar (CTO), Merel (Product Owner), Alison (Product Support Team), Jorge (Data Engineer Lead), Pambo (Backend Engineer Lead), Syahmia (QA Lead), Kiky (QA), Harry (QA Internship) and Khalid (QA Automation Engineer) who involved in this migration to coordinate during the migration and led the migration to minimum risks. Superb!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4eb472e6774a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/minimal-downtime-database-migration-from-mariadb-galera-cluster-to-cloudsql-for-mysql-at-production-4eb472e6774a">Minimal Downtime Database Migration from MariaDB Galera Cluster to CloudSQL for MySQL at Production…</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lessons Learned from Managing NiceDay Services (Docker) by Using Rancher (Version 1.x)]]></title>
            <link>https://medium.com/niceday-dev/lessons-learned-from-managing-niceday-services-docker-by-using-rancher-version-1-x-3ccf3450211e?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/3ccf3450211e</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[rancher]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <dc:creator><![CDATA[Ridwan Fajar]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 07:48:10 GMT</pubDate>
            <atom:updated>2022-07-04T07:48:10.770Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lessons Learned from Managing Docker Services by Using Rancher (Version 1.x)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*_bHfAw5tflKtuiJ8Eebm3g.png" /><figcaption>Figure 1 — Overview of Rancher v1 Cluster</figcaption></figure><h3>Overview</h3><p>Moving from traditional deployment to container-based deployment required a lot of steps. First, we had to understand how container-based deployment such as using Docker work. Second, we had to know how could we orchestrate them in single place easily. In that case, two of my colleagues were choosing container management for Docker implementation at Sensehealth B.V. then end up with Rancher v1.</p><p>Rancher is made by Rancher Labs. It has container orchestration called Cattle Engine. Rancher consists of one server node and multiple agent nodes. They are communicating mostly via HTTP or HTTPS. Rancher has a really nice admin page that help us a lot while we are working for day to day operation on container-based deployment.</p><p>In this article, I want to share my personal experience while I am working as an infrastructure engineer at Sensehealth B.V. which works with multiple deployments from developer team such as from frontend, backend and data team.</p><p>After more than two years, I have a good overview for using Rancher v1 for container management. Here we go!.</p><h3>Terminology</h3><p>Before continuing to another section, here are some importants terminology that should you know first:</p><ul><li>Rancher Server: a node that control over multiple agent nodes</li><li>Rancher Agent: a node that run and control the deployment also communicate to the server node to confirm the deployment</li><li>Environments: A group of multiple stacks that server for its own purposes (e.g.: Staging, Production, Sandbox, etc.)</li><li>Stacks: a group which hold multiple services</li><li>Services: Run the Docker image as a service. It will run the image over multiple agent nodes.</li><li>Cattle: Orchestration engine that powered Rancher v1</li></ul><h3>A. Operational</h3><h4>A.1. Manage multiple services with Rancher Stack</h4><p>Let say that you have a collection of services that run on same project. You have backend service, frontend service, worker service, scheduled job service, push notification service and so on.</p><p>Grouping those services in single place might let those services more organized. Rather than run the service ungrouped. You are also able to apply a task upon those services such as stop or restart those services together. On the other hand, you could see the status of your services under that stack and apply same action to those particular services such as upgrading, stopping or restarting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B8rNqH9W5R3hMyKNsI4yjA.png" /><figcaption>Figure 2 — Managing services within Rancher v1 Stack</figcaption></figure><h4>A.2. Easily scale our service</h4><p>I only need to choose one of services that required to be scaled up. Then, I could increase or even decrease the amount of containers that I want. It will be deployed over all rancher agents or add new container in same rancher agent. Depending to the specified setting for that service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*OqRle2kS5UOFP_BJq3LzNQ.png" /><figcaption>Figure 3 — Scaling service in Rancher v1</figcaption></figure><h4>A.3 Manage multiple stacks with Rancher Environment</h4><p>Separating stacks from different context gives the team the ability manage them easily. Moreover, our team could limit someone from accessing some environments which are not allowed to get into it.</p><p>It’s not only stop there, you may have different orchestration engines or specific ACL rules for users who are going to access that limited enviroments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJHPX_gqxb2GN8XLE5Z2ww.png" /><figcaption>Figure 4 — Managing Stacks at Rancher v1</figcaption></figure><h4>A.4. Providing useful template for Etcd deployment from Community Catalogue</h4><p>When I wanted to deploy Etcd for configuration management, Its really tricky if I have to deploy it manually. Then, Ricky suggested me to check catalog from Rancher where the community provides various templates. It will be deployed to Rancher easily.</p><p>So I choosed Etcd template from that catalog then I have it as a stack within particular environment. I don’t have to spend time a lot to deploy it. Moreover, it could be linked to another services that required Etcd as it’s configuratio management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QIjEKqHKwGcaNLz8Tmkmw.png" /><figcaption>FIgure 5 — Deploy service using Rancher v1 Catalog</figcaption></figure><h4>A.5. Monitor Rancher Agent by using Rancher Exporter</h4><p>It’s not officialy Rancher template, but we can integrate it to our Rancher environment easily. We have to make sure our rancher agents are always available every second. Once there is an incident, I could get the alert from Prometheus and receive it from my OpsGenie app.</p><p>At least it could help me to know about the status of every rancher agent by using Rancher Exporter without frequent monitoring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2SkGxqb1nBMoRQ9_UZEKMA.png" /><figcaption>Figure 6 — Monitor Rancher Agent using RancherExporter for Prometheus</figcaption></figure><h4>A.6. Manage Docker Registries</h4><p>Currently, we only have DockerHub as our Docker registry. But I could say we could have more than one Docker registry in the future and add it to our Rancher environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qwNLFZoVdNvral_og7G69g.png" /><figcaption>Figure 7 — Managing Docker Registries in Rancher v1</figcaption></figure><h4>A.7 Mark the Service Deployment by Scheduling</h4><p>This is the thing that might be crucial. You can deploy specific containers in particular rancher-agents. Might be some containers will not be deployed on rancher-agents with high server specification.</p><p>Ricky used this technique to deploy chat service (based on Ejabberd) in rancher agent with more high specification. So other containers will not be deployed there. The resource in that rancher agent will be consume by chat service only.</p><h3>B. Security</h3><h4>B.1. Manage ACL for infrastructure team</h4><p>Not every environment should be accessible to everyone. I can limit someone who is granted to access “Infrastructure” environment. Of course, only infrastructure team which are able to access that environment. The other Rancher user wouldn’t be allowed to interact with infrastructure team related services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*soRxbUVkPSqwazLXoXzVIw.png" /><figcaption>Figure 8 — Manage ACL for team</figcaption></figure><h4>B.2. Integrated SSL Certificate management</h4><p>Most of our services required SSL certificate. That’s why we couldn’t locate it in every rancher agents. Therefore, we have to manage it in centralized way so we only need to load it in built-in load balancer and attached it to particular subdomain or domain name for particular services.</p><p>I could also check the expiration of some SSL certificates through this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7D3iDAyc-PkSLs8qgLLpVQ.png" /><figcaption>Figure 9 — Manage SSL certificates in Rancher v1</figcaption></figure><h4>B.3. Manage secrets</h4><p>Secrets are kind of variables that should be kept from someone. It might be credentials or environment variable setting. You can manage those secrets in Rancher for some services who need it. On the other hand, we could reuse some secrets for multiple services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eHS99ieHgYreb0Domda7hw.png" /><figcaption>Figure 10 — Manage secrets in Rancher v1</figcaption></figure><h3>C. Integration</h3><h4>C.1. Adding new Rancher Agent to existing cluster easily</h4><p>I have tried to new host in some environments. To add new rancher agent, you only need to run rancher agent service within new node. Then, you can click “Add Host” in “Hosts” menu at Rancher Admin.</p><p>You will be asked to run Curl operation for joining new rancher agent to existing rancher cluster. Under a minute, it will be running with other rancher agents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*VQvYdn2TDnlHRleHcsHyzA.png" /><figcaption>Figure 11 — Manage Hosts which are running as Rancher Agent</figcaption></figure><h4>C.2. Trigger service deployment with Rancher Webhook</h4><p>In some cases, Rancher could perform auto deployment for specific tag if the latest image for that tag is published. So for example, in the end of backend release process, new image for backend service will be created. Then, Rancher will receive an event from Docker Hub that will ask Rancher to pull new image for that specific tags. Usually, within a second, backend service will be upgraded to that latest image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SOTmH43zuXktsNWQU14z3w.png" /><figcaption>Figure 12 — Manage Rancher Webhook for DockerHub</figcaption></figure><h4>C.3. Built-in Load Balancer management with HAProxy for Exposing new Service</h4><p>One of key features of Rancher is load balancer. They provided us HAProxy which has a built-in rule editor that could help the infrastructure team to manage service rules.</p><p>Usually, I worked for exposing some services to public internet or enable some restrictions to some services such as allowing some IP Addresses to access confidential services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KCroEffGcjxLGVazo4ISAQ.png" /><figcaption>Figure 13 — HAProxy load balancer as built-in web server for Rancher v1</figcaption></figure><p>We could create HAProxy rule by defining the protocol, request endpoint, port on host, targeted service, service port and label for that rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9n8VOQvGoftTqMKITncVsg.png" /><figcaption>Figure 14 — Manage HAProxy rules for particular services at Rancher v1</figcaption></figure><p>We could also attach any SSL certificate to particular service who need HTTP connection.</p><h4>C.4. Integrate existing non-container services as External Service</h4><p>I think this is one of key features in Rancher. Some services need to access databases. We could build the database within Rancher cluster but it might be less effective since database service might overwhelm other services.</p><p>That’s why if we have existing databases or plan to run database in separate place, “External Service” is the answer.</p><p>We could point that external service to some accessible IP Addresses from our legacy databases then it would be linked to services who required those databases. Then, external databases might communicate with services in Rancher cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vdg8lbKzomWIdhAOUMw0wg.png" /><figcaption>Figure 15 — Rancher external service that could bridge services in Rancher Cluster with other services outside the cluster</figcaption></figure><h4>C.5 Send Docker logs to ELK stack using Gelf Driver</h4><p>This is the part i really enjoy. There are around 50 services that send their Docker log to ELK stack by bridging it using Gelf Driver. So our team could reduce the amount of disk usage within rancher agents and let ELK Stack manage those Docker log.</p><p>Moreover, I could perform error tracing for some services in integrated dashboard by using Kibana. With the power of Elasticsearch query, searching for errors in specific service or among services, it’s more handy than opening service page and looking for error in its log browser.</p><h3>Conclusion</h3><p>Working with Rancher v1 consistenly since 2018 gave me a lot of overview about managing Docker services by using container orchestration (Cattle) and container management (Rancher v1 itself).</p><p>It should be enough as first step to know about the main task of container orchestration and container management. If I should move to another container orchestration such as Apache Mesos, Kubernetes, Nomad or OpenShift, I might not be surprised because I have those common experiences with Rancher v1.</p><p>On the other hand, there are a lot of container managements in the market such as Apache Marathon, AWS Fargate and Kubernetes-like in some cloud providers. Rancher alone release Rancher v2 as the successor of Rancher v1 but it built for Kubernetes alone.</p><p>With this experiences, it gave me a lot of knowledge that I didn’t expected before. Thanks infrastructure team!</p><blockquote>Ricky Hariady who introduced me to Rancher Cluster and infrastructure team who are always helping me work with Rancher for infrastructure-related tasks.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ccf3450211e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/lessons-learned-from-managing-niceday-services-docker-by-using-rancher-version-1-x-3ccf3450211e">Lessons Learned from Managing NiceDay Services (Docker) by Using Rancher (Version 1.x)</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL Database Change Management with Django Migration]]></title>
            <link>https://medium.com/niceday-dev/postgresql-database-change-management-with-django-migration-b4d50458c1a0?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/b4d50458c1a0</guid>
            <category><![CDATA[django]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Ridwan Fajar]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 07:48:05 GMT</pubDate>
            <atom:updated>2022-07-04T07:48:05.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A7xEXXYaWIs4bY20vFFW3g.jpeg" /><figcaption>My weevil portrait which I took at Ciwangun Indah Camp, West Bandung Regency, West Java Province, Indonesia</figcaption></figure><p>How to track changes and in database structure and dataset after new version of backend service deployed? How to revert it back if the deployment has an issue on database side?</p><p>I want to share my perspective about trackable database structure change as former backend team and currently as infrastructure team.</p><p>Its almost 4 years for NiceDay Nederland (formerly known as SenseHealth B.V.) to use Django as backend framework. For first two years, I involved as backend developer and write some migration scripts which is very useful to have our changes on our Python scripts. We use PostgreSQL for main transactional database and track every changes on that database.</p><p>Then after two years, I am fully joining Infrastructure Team and sometime handle backend developer requests regarding deployment. From my perspective, I could apply database change without touching SQL syntax such as CREATE TABLE or ALTER TABLE. Just let the migration scripts running. I could revert the migration and database change based on our strong “Deployment Request Document” which contain scenario for applying changes or revert it.</p><p><a href="https://docs.djangoproject.com/en/3.2/howto/writing-migrations/">Writing database migrations | Django documentation | Django</a></p><p>Django migration log is also helpful. You might find some exceptions and trace it easily if you encountered problem during migrations. You might check which migration that has been applied before. And about your dataset, don’t worry. We have consistent dataset because backend team test the migration script before create a request to infrastructure team for deploying new version of backend service.</p><p>By using Django Migration Tools, our life is easier.</p><ul><li><a href="https://docs.djangoproject.com/en/3.2/topics/migrations/">Migrations | Django documentation | Django</a></li><li><a href="https://docs.djangoproject.com/en/3.2/ref/migration-operations/">Migration Operations | Django documentation | Django</a></li></ul><p>Whatever the tools, keep your database structure change on migration script. You might alter your database structure manually after the deployment or revert it back whenever its needed. But that might time consuming workflow for your process.</p><p>And please keep in your mind, backup your dataset regularly just in case you might encounter disaster during applying migration script. Its also a best practice which introduced by ISO 27001:2013 for Information System Security Standard.</p><p>Thanks for reading! Have a nice day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4d50458c1a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/postgresql-database-change-management-with-django-migration-b4d50458c1a0">PostgreSQL Database Change Management with Django Migration</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A scale up story]]></title>
            <link>https://medium.com/niceday-dev/a-scale-up-story-d0a71bfee1ef?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/d0a71bfee1ef</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[netherlands]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Umar Nizamani]]></dc:creator>
            <pubDate>Mon, 04 May 2020 08:09:29 GMT</pubDate>
            <atom:updated>2020-05-04T08:09:29.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tioNWbaNHptH_9rAqXCtbw.jpeg" /><figcaption>Credits: <a href="https://unsplash.com/@sanfrancisco">https://unsplash.com/@sanfrancisco</a></figcaption></figure><p>In these tough times we are all trying really hard to play our part to help bring the world back to normal or perhaps the ‘new’ normal that comes once we have contained and controlled this pandemic.</p><p>At <a href="https://nicedaycoaching.com/">NiceDay</a>, we have always believed the future of mental health care to be need driven. This means providing care to people who need it the most and at the time that they need it. This means providing care to clients exactly when they need help no matter where they are.</p><p>In this time where the world needs new ways to work digitally, we are helping make sure that thousands of treatment sessions a day that might not have taken place can happen. Our entire team has been hard at work to embrace all the mental health organisations that want a new way to provide mental health to their clients, a solution that is not just video calling at a distance but a completely new way to work.</p><p>In the last few weeks we have seen an immense growth in our user base and have grown over 20x. Such a surge in growth in a short period is no easy task to handle but we faced this surge of people looking for help by the entire team improvising our roles to provide a fundamentally great NiceDay experience to everyone who needed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZdPTvdtQG778q7VCT2Gzww.png" /><figcaption>Incoming Requests</figcaption></figure><p>As such a growth spurge is a very new challenge for us, I want to share our story, what we did to facilitate all the users and the moves we had already made in the past which helped us a lot in these times.</p><h3><strong>Scaling Up 🚀</strong></h3><p>We knew from early March that if the situation with the pandemic was to get worse, NiceDay might become the core tool of choice for our partner organisations but we did not have any idea on the number of users to expect and when to expect them.</p><p>In the 2nd week of March as a lockdown was introduced in the Netherlands, we were bracing for a surge but were still uncertain on the impact this might have on us.</p><p>The next Monday we were seeing a spike unlike ever before. ~50x more signups in a single day then the previous week. The servers were being crushed and everything was slowing down to almost a halt, it was a bear hug from all our new users!</p><p>Having a pretty stable infrastructure that I have <a href="https://medium.com/sense-health/revamping-a-legacy-backend-1-1429a4ce77cb">detailed in the past</a> and an extensive monitoring + alerting setup. We quickly found out that our chat database (<a href="https://mariadb.org/">MariaDB</a>) was completely overwhelmed with all the incoming requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiRxqgI46KFHXcIXGboYeg.png" /><figcaption>Load across all the entire MariaDB cluster</figcaption></figure><p>Having a cluster of MariaDB with all masters, we immediately upgraded one of our nodes to be 8x its size and specified our load balancer (HAProxy) to use this instance first for all incoming requests and only if this server was down to redirect requests.</p><p>This ensured MariaDB had enough CPUs to perform all incoming queries and increased the <a href="https://mariadb.com/kb/en/mariadb-memory-allocation/#what-is-the-buffer-pool">buffer pool size</a> with the new amount of RAM we had to further speed up performance.</p><p>With the database stabilised, we now had an enormous load on our chat server (<a href="https://www.ejabberd.im/">Ejabberd</a>) which was getting all these responses from the database really fast and getting all these requests from our end users but didn’t have the capacity to process them fast enough. All cores were utilised a 100% and as the chat server was running in a container on a server which had other services running on it as well, it was slowing down everything on the server as the cache kept getting smashed by Ejabberd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VneU3N5pHIEQqr5XoOnxuw.png" /><figcaption>CPU load on the Rancher Agent with Ejabberd</figcaption></figure><p>We spawned a new server which was 8x the size of our current chat server and pinned only the chat service to this server and voila, our entire service stabilised. The response times on our main backend were still a bit slow but the whole experience of the product was quite good and the bear hug was converted to a tight embrace :) We had survived the first wave!</p><p>The 1st wave of problems solved, our infrastructure team decided to do a daily morning standup everyday from then on to monitor the situation. This worked specially great as our infrastructure team is in our Bandung office in Indonesia which means their 9 AM is 4 AM CEST and all our users are in CEST! We would look at the statistics from the previous day and upgrade our servers accordingly. The goal was to make sure no server reached more than 30% usage, we were saving rest of the capacity for unknowns that might come up during this time of scaling up.</p><p>While the infrastructure team was busy optimising the servers to make sure all clusters were sufficiently capable to handle incoming load, the development teams were in action to pickup quick stories to improve the experience of our users.</p><p>With so many new users our support team was getting overwhelmed with a huge amount of questions! Dutch speaking members of our tech team joined the support team to help investigate technical questions and we formed an FAQ sheet to identify key questions coming in from users.</p><p>As a problem got reported more often, the UX team would brainstorm with someone from the tech team and identify a quick solution for it and the dev team would pick it up to release as a hotfix! This way, we made sure new users can have a great experience and our support teams aren’t overloaded with requests so they can answer all incoming questions in a short time.</p><h3><strong>The 2nd wave 🌊</strong></h3><p>With the user growth we were seeing, we were running into practical restrictions that we didn’t care about in our initial development. We had for e.g a limit of 1000 therapists that would be visible in our portal, as we were loading only 1 page of data instead of looping through all the therapists available in our product but no-one tested the behaviour if you had &gt; 1000 therapists!</p><p>After a week and a half of hot-fixes and rapid releases with the QA team working extra hard to do their testing, we were starting to receiving great reviews from lots of teams about how great an experience they were having with NiceDay!</p><p>Even in this time of rushing to scale up, members of our team didn’t forget their sense of humour ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*VubDamEf4gCWBeAbv8Urww.png" /><figcaption>Our newly added server. rancher-agent-<strong>CV19 </strong>reporting for duty!</figcaption></figure><h3><strong>Things start going sour</strong></h3><p>Meanwhile, we had almost our entire infrastructure under control but were still facing high load on our chat server. Even with 64 cores our chat server was still under immense pressure and reaching up to 80% usage at peak times!</p><p>We knew we had some inefficiencies in the way we load chat history in our code and were already busy building a hot fix for it but time was running out as our clustering was failing in the chat server due to an unknown bug in our setup and our single instance was already pushed to 64 cores, the only option available above this was a 96 core system which we had already setup for standby to take over!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRpTB9-Q3jr60HAjTSB8DQ.png" /><figcaption>Even with a 64 core node, the server is heading towards certain failure!</figcaption></figure><p>Our infrastructure lead got a great clue when going through the <a href="https://mariadb.com/kb/en/information-schema/">information schema</a> in the database of our chat server and noticing that 2 of the tables <em>mod_caps</em> and <em>sr_user</em> were queried over a billion times! Having worked with Ejabberd for a few user, we knew these tables were used by the Shared Rosters feature which we use to add users into groups to allow users in a group to see each others presence status (i.e whether they are online or not).</p><p>With the pressure mounting and we approaching peak hour of the day, we saw the load of our chat server crossing 100% we were already getting reports of chat running slow and were running out of time!</p><p>In this moment of pressure, we realised that the problem was rooting from the fact that <em>shared_roster </em>was doing a query in the database every time anyone had changed their presence status (i.e went online/offline/busy) and then had to broadcast this change to every user!</p><p>This small presence feature turned out to have a deadly chain reaction completely crumbling our chat server. We immediately shut down the feature and saw the load on the server go down to ~5%!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TrTMBuEbAiTRalu3TVlkQ.png" /><figcaption>I would like to ski down that slope!</figcaption></figure><p>While fixing the problem, our intention was to enable caching in the Shared Roster feature in Ejabberd but unbeknown to us this actually wasn’t supported in the version of Ejabberd we were using and hence caused an incorrect configuration error which is why Ejabberd had just shut down the feature which shed all load!</p><p>This just goes to show how much knowledge and luck you need in high pressure situations like this to reliable handle problems.</p><p>There is a lot to share about the last few weeks we have had and there are a lot of learnings we have had, specially with hindsight to look back at the decisions we made in the past that helped us immensely in our current moment of growth.</p><p>In the next article in this series, I will be sharing more about the technical developments we were already busy with which have allowed us to move forward and support these new users quickly and provide them with a great experience!</p><p>If you are looking to join a team in an exciting period, join us! See some of our vacancies here: <a href="https://careers.nicedaycoaching.com/">https://careers.nicedaycoaching.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0a71bfee1ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/a-scale-up-story-d0a71bfee1ef">A scale up story</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infrastructure Migration with AWX (Ansible Tower) Workflow]]></title>
            <link>https://medium.com/niceday-dev/infrastructure-migration-with-awx-ansible-tower-workflow-d137acb9fb0?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/d137acb9fb0</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[awx]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[ansible-tower]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ridwan Fajar]]></dc:creator>
            <pubDate>Thu, 30 Jan 2020 06:46:01 GMT</pubDate>
            <atom:updated>2020-05-27T06:42:19.851Z</atom:updated>
            <content:encoded><![CDATA[<h3>Preface</h3><p>By mid-August 2019 our team was trying out new environments on <em>Google Cloud Platform</em> (GCP) for the region Netherlands. We had existing <em>Infrastructure As a Code </em>(IaaC) projects which consisted of <em>Terraform</em> and <em>Ansible</em>. We used them to manage our infrastructure in an <em>OpenStack</em> environment.</p><p>Since IaaC allows recreating an infrastructure in another environment, we were trying to run Ansible upon our new instances on GCP. We needed to reconfigure some variables in the new instances but we did that in an unorganized manner. We ran the templates independently and not in the right order for a certain cluster-set of our databases.</p><p>After all, we turned to AWX Workflow in order to organize our scattered templates. That reduced our time to find and specify parameter for each template. Below is the story of our infrastructure team experience with AWX Workflow.</p><h3>Exploring AWX Workflow Interfaces</h3><p>First of all, when you open the Templates menu from the left-side bar you see the green “plus” button (on the right) which allows creating two different types of templates. You can create Job Templates or Workflow Templates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ln34gU1v5qyiO1C_DI6VMA.png" /></figure><p>If you have an existing template you can include it in the Workflow and arrange the templates in your desired order by using theWorkflow Visualizer page (see the image below).</p><p>The job designer can choose which jobs need to be included into the workflow and then apply Inventory to all the jobs.</p><p>An inventory is a collection of hosts connected to the AWX template. Jobs can be launched against those hosts. The image below illustrates how an inventory could be used in AWX workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPrV5pi9oNCaXuzoz4fmJQ.png" /><figcaption>Choosing inventory in Workflow Visualizer</figcaption></figure><p>After opening Inventory you can choose another template if necessary:<br>- Click on a job.<br>- Click the blue “plus” button when it pops up above the job’s node.<br>You can now choose any template that needs to be a part of your workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4NgOwc1syJ9yym_BWQAGfg.png" /><figcaption>Choosing template to be added into another Jobs node</figcaption></figure><p>Since Ansible uses variables, you can override a variable included in a job node with a global variable on the workflow level. It might simplify your job since you won’t need to define variables for each job node while you are in Workflow Visualizer. The pre-filled form will pop up when you try to launch the workflow (see the image below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slgDnuFYBQABkVl3Hv7xcg.png" /><figcaption>Creating survey for the workflow</figcaption></figure><h3>Running the Workflow</h3><p>The image below illustrates how the workflow runs templates one by one:</p><p>1. The PostgreSQL cluster workflow is initiated by running the templates for installing common package(s) and monitoring tools.</p><p>2. Templates for running the PostgreSQL setting as a master are executed.</p><p>3. The backed-up database gets restored.</p><p>4. The slave node gets set up.</p><p>5. The workflow gets finalized by enabling the backup mechanism on the slave node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XqIZU9oomHwp_672gm8vZA.png" /><figcaption>Workflow for PostgreSQL Cluster</figcaption></figure><p>Jobs can be synchronous or asynchronous (the image above illustrates a chain of synchronous jobs). A synchronous job gets executed only when the previous one finishes. On the other hand, asynchronous jobs get executed in a stand-alone manner and they do not have to wait for other jobs to finish.</p><p>The image below illustrates how the Restore and Backup templates work independently after the template for installing MariaDB Cluster has finished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuT83POIluhaF7z_1g8FzQ.png" /><figcaption>Workflow for MySQL Cluster</figcaption></figure><p>It is possible to combine multiple workflows into a single large workflow, but you need to make sure your workflow(s) are well tested and can be executed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3Rf7RYWBvZd9lSRKq8Bkw.png" /><figcaption>picture 6</figcaption></figure><h3>Result</h3><p>Running our updated workflow takes 13 minutes and 49 seconds, that includes all the templates for building a PostgreSQL cluster, restoring the latest databases and applying the backup procedures.</p><p>Our previous workflow for MariaDB cluster required 59 minutes and 13 seconds to run all the templates for building the cluster-set, restoring the latest databases and applying the backup procedures.</p><p>It took us almost one day to develop the new template. As a result, the repetitive tasks were automated and we no longer need to run independent scattered tasks manually. We no longer need to waste time and run templates from the admin page</p><h3>References</h3><ul><li><a href="https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html">https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html</a></li><li><a href="https://docs.ansible.com/ansible-tower/latest/html/userguide/workflow_templates.html">https://docs.ansible.com/ansible-tower/latest/html/userguide/workflow_templates.html</a></li><li><a href="https://www.unixarena.com/2019/03/ansible-tower-awx-creating-workflow-template.html/">https://www.unixarena.com/2019/03/ansible-tower-awx-creating-workflow-template.html/</a></li><li><a href="https://www.youtube.com/watch?v=22vaD3QH1rg">Ansible Tower Workflow Demo on Youtube</a></li></ul><blockquote>Thanks to Leo Bouguslavskiy who helped me a lot for reviewing this article</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d137acb9fb0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/infrastructure-migration-with-awx-ansible-tower-workflow-d137acb9fb0">Infrastructure Migration with AWX (Ansible Tower) Workflow</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enable Chat Online Status within NiceDay Apps]]></title>
            <link>https://medium.com/niceday-dev/enable-chat-online-status-within-niceday-apps-8f67315c3b96?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/8f67315c3b96</guid>
            <category><![CDATA[xmpp]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[ejabberd]]></category>
            <category><![CDATA[online]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Muhammad Yusuf]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 09:19:47 GMT</pubDate>
            <atom:updated>2020-03-24T02:25:24.124Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chat Online Status in NiceDay</h3><p>I’d like to walk you through a feature development in our app NiceDay and I thought a nice example of a complex feature to share would be enabling chat <em>online status</em> in our product.</p><p>We want to leverage <em>online status</em> in our product to improve the user experience, namely when a client wants to interact with one of the professionals. The feature is easy to describe: it boils down to showing the online availability of a professional to the clients and vice versa, but implementing it with an external chat service (Ejabberd) and a custom Django backend for authentication can be quite tricky.</p><p>To enable this feature, we decided to leverage Roster items in the Ejabberd chat server which we can create directly from our Django backend when a user connection is created.</p><h3>Ejabberd API Configuration</h3><p>To enable this feature, we decided to leverage Ejabberd’s internal <a href="https://docs.ejabberd.im/developer/ejabberd-api/">REST API.</a> This allows us to control behaviour in the Ejabberd chat server using REST-based methods. To do this, we first created an internal admin user with permission restricted to only exactly the API calls we needed. We follow a strict privacy first development lifecycle, which means every API/admin gets access only on a need-to-know basis.</p><p>To enable Ejabberd APIs, in the <strong>listen</strong> section of the Ejabberd configuration, we set up <em>mod_http_api</em> to be accessible through <strong>/api</strong> endpoint, as you can see in the snippet below:</p><pre>listen:<br>  -<br>    port: 9999<br>    ip: &quot;::&quot;<br>    module: ejabberd_http<br>    request_handlers:<br>      &quot;/api&quot;: mod_http_api</pre><h3>Implementation in our Django Backend</h3><p>We implemented this as an external service within our Django backend which belongs to the Django package system. We wrapped this external service with helper functions so that the other apps could make use of this Ejabberd Django app when required for other features as well.</p><p>These are the standard payloads we used to interact with <em>add_rosteritem</em> and <em>delete_rosteritem</em> API calls that we required to create/remove rosters.</p><pre>POST /api/add_rosteritem<br>{<br>  &quot;localuser&quot;: &quot;user1&quot;,<br>  &quot;localserver&quot;: &quot;myserver.com&quot;,<br>  &quot;user&quot;: &quot;user2&quot;,<br>  &quot;server&quot;: &quot;myserver.com&quot;,<br>  &quot;nick&quot;: &quot;User 2&quot;,<br>  &quot;group&quot;: &quot;Friends&quot;,<br>  &quot;subs&quot;: &quot;both&quot;<br>}</pre><pre>HTTP/1.1 200 OK<br>&quot;&quot;</pre><pre>POST /api/delete_rosteritem<br>{<br>  &quot;localuser&quot;: &quot;user1&quot;,<br>  &quot;localserver&quot;: &quot;myserver.com&quot;,<br>  &quot;user&quot;: &quot;user2&quot;,<br>  &quot;server&quot;: &quot;myserver.com&quot;<br>}</pre><pre>HTTP/1.1 200 OK<br>&quot;&quot;</pre><p>When a client and a professional establish a connection with each other, a roster item is created which can be used by the app (using XMPP) to poll the presence of a user in the roster and make <em>online status</em> visible in the app and on the web portal. Ejabberd itself has a capability for handling duplication whenever someone performs multiple <strong>add_roster_item</strong> operation.</p><p>Roster Item is a basic functionality used by Presence API from Ejabberd for showing <em>online status</em> of a user of XMPP.</p><h3>SDK Specification</h3><p>Since we handle logic related to adding/removing Roster in the backend, responsibility of our SDK is only to provide the app and the web portal with the following capabilities:</p><ul><li>Sending availability status of the user.</li><li>Receiving availability statuses of the user’s contacts.</li></ul><p>We utilise the following availability status types supported by Ejabberd:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*Y5JNPbG_eQr2RkU4X2xddA.png" /></figure><h4>Send Initial Presence</h4><p>Send the following XML to the server to tell that the user is available:</p><pre>&lt;presence/&gt;</pre><p>By sending this, the user will be seen as <strong><em>online</em></strong> (or <strong>available)</strong> by their contacts.</p><p>Without sending this, the user won’t get an update on the availability status of their contact.</p><h4>Send Availability Status</h4><p>We utilise this when a user wants to be seen as <em>away</em>, <em>busy</em>, or <em>appear offline</em>. This will send the following XML to the server to tell the user availability status.</p><pre>&lt;presence <a href="/service/mailto:to=&#39;juliet@example.com">to=&#39;juliet@example.com</a>&#39;&gt;<br>    &lt;show&gt;away&lt;/show&gt;<br>    &lt;status&gt;Having a spot of tea&lt;/status&gt;<br>&lt;/presence&gt;</pre><h4>Subscribe to User Presence Change</h4><p>The subscription is responsible for a callback upon the arrival of a contact availability. XML of the following format will be received when a contact’s availability status has changed:</p><pre>&lt;presence from=&quot;alice@wonderland.lit/rabbithole&quot;<br>          to=&quot;sister@realworld.lit&quot;&gt;<br>&lt;/presence&gt;</pre><p>The SDK is also responsible for converting this XML to a TypeScript type that can be consumed by the app and the portal portal.</p><h3>Implementation in the NiceDay app</h3><p>We defined the behaviour of this feature in the app as described below:</p><ul><li>The app will send initial presence to broadcast its <em>available</em> status once it is connected to the chat server.</li><li>The server will automatically broadcast <em>unavailable</em> status once the app is no longer connected to the chat server (currently the app disconnects from the chat server once it gets sent to the background or killed by the user).</li></ul><p>When a contact is online, the app will show “<em>Online</em>” text below the name of the contact in the chat room.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/0*AZTUR7DdH4knFytw.png" /></figure><h3>Implementation in the web portal</h3><p>The server automatically sets the web portal user’s availability status based on whether the user is connected to the chat server or not. We also provide the user with an ability to change their status manually. The user can choose from o<em>nline</em>, a<em>way</em>, <em>busy</em> and a<em>ppear offline </em>statuses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*WhN4_ozTiPuXEgMc.png" /></figure><p>In some particular cases, the web portal automatically sets the user’s availability status. After a period of inactivity, we set the user’s availability status to<em> away</em> and when the user is in a video call, we set their availability status to <em>busy</em>.</p><p>The user may log in to more than one portal instances (e.g open the portal in another tab or in a different browser on another computer). To make their availability status consistent, we sync the statuses between those instances. So if the user sets their availability status to <em>away </em>in one portal instance, the same status will be passed on to all the other existing portal instances.</p><h3>Conclusion</h3><p>It is easier to interact with Ejabberd through the Ejabberd API. In this case we enabled the Roster Item operation through its API while keeping the service secure enough and ensuring that we grant permission to the APIs strictly on a need-to-know basis.</p><h3>References</h3><ul><li><a href="https://docs.ejabberd.im/developer/ejabberd-api/admin-api/">Ejabberd API Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f67315c3b96" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/enable-chat-online-status-within-niceday-apps-8f67315c3b96">Enable Chat Online Status within NiceDay Apps</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we test our product]]></title>
            <link>https://medium.com/niceday-dev/how-do-we-test-our-app-29e45b38164e?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/29e45b38164e</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[qa]]></category>
            <dc:creator><![CDATA[Kurnia Jaya Eliazar]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 08:01:01 GMT</pubDate>
            <atom:updated>2019-03-06T18:26:28.448Z</atom:updated>
            <content:encoded><![CDATA[<p>December 2018 marked exactly one year since we started the development of <a href="https://niceday.app/">NiceDay</a>. In this article, we would like to focus on how we implement automation test for our product and we will also share short stories about how we release, distribute and test our app.</p><h3>Releasing and App distribution</h3><p>Before we talk much about testing, let’s start with how our app is being distributed to our users. First, we build our product for three environments alpha, beta, and production. To build and distribute three types of build flavors we use <a href="https://fastlane.tools/">Fastlane</a>, <a href="https://travis-ci.com/">Travis</a>, and Slack. Whenever App/Web team are ready with their release branch, using a single Fastlane command any developer in the team can easily release the app.</p><p>In a simple description, Fastlane will trigger GitHub to create a tag and push last updated change-log in the release branch. When a release tag is created, it will trigger Travis to run several tests first such as code formatting, code quality, and unit test.</p><p>After an app is successfully built, Fastlane will release it to the appropriate store and send a report to slack that the app was successfully released. Since we are using React Native we also have the option to do native or JS only release:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*WWaSu1jLKDSQN9yR9kRT-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*xTSQlGKW_fvzcpkj3BkJiQ.png" /></figure><h3>Testing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*fNrCneyp7326JYRWbA_PSQ.png" /></figure><p>At present we have eight types of tests, three of which we already discussed in the first part (code formatting, code quality and unit test). So let’s discuss the rest:</p><ol><li><strong>Change-log based test</strong>, this test is used only for patch/minor release. QA team will only test app based on change-log text that contains features that have been added, fixed, changed and removed.</li><li><strong>Regression test</strong>, with more than 130 test cases QA team will do complete tests for a major release, especially in the beta and production environment.</li><li><strong>Scheduled test</strong>, is the test that the QA team initiates to check the main feature and test out of test cases that we already have. Commonly we schedule regularly 1 hour, 2 days a week for such tests.</li><li><strong>Daily test, </strong>is the test that is constantly running every day to check the stability of our app. It contains important test cases such as register, login, forgot password, log out, etc. These are automated tests that we run every morning before business hours.</li><li><strong>Integration test </strong>is the test that we plan to develop in Q1 of 2019. These will fully test a feature that works across different platforms such as App, Web, and Backend.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*yPcdsMXk_ht0JH1agM_vmA.png" /></figure><p><strong>Daily testing</strong></p><p>This testing is also known as UI test or automation testing. The main reason for this testing implementation because we need to check the stability of our app. Since it is related to stability, most of the tests are repetitive and since it is a repetitive task it should be automated. For our tech stack, we have chosen Appium, Selenium, and Pytest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*v7o1KblDSUZ00f04GZHVSA.png" /></figure><p>For the testing script, we have set up three branches for each release type (Alpha/Beta/Production). This also makes it easy to manage a different feature than the app has built. For example, we have a chat online status feature but the feature still in alpha, so we create the test script for the chat online status feature in the develop branch when we release the application to alpha. Once the feature releases to beta in the App, we also follow the process and release the test script to Beta.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*16TWc_6zWsncOEXq" /><figcaption>Picture 5 Branches</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*r6lfeWF_OeIN6YdDr0y8xg.png" /><figcaption>Test Process</figcaption></figure><p>We also set up several parameters in our test scriptto make testing easier</p><ol><li>-I Y &gt; pytest_report.log, to enable Slack integration</li><li>-D , to select <strong>a real device</strong> that we would like to use for test</li><li>-B , to select the <strong>browser</strong> that we would like to use for test</li><li>-E , to select an <strong>environment</strong> that we would like to use for test</li></ol><p>Full of script example</p><pre>pytest -s -v -D ANDROID_DEVICE_HIGH -E ALPHA_ENV -I Y &gt; pytest_report.log</pre><p>Generally, in a single day, there would be 18 tests that we run locally on our machine as we show in the Test Process image above. In the first generation of development, we have set up the test process in our local machine. Why?</p><ol><li><strong>We would like to run it in real devices.</strong></li><li><strong>It is easier to manage.</strong></li><li><strong>Somehow test script gives a different result in the different machine.</strong></li></ol><p>In the future, we will start implementing this in Travis but for now, our focus is to reduce QA team workload. Last words from us:</p><blockquote>“ Test Early. Test Often. Test Automatically “</blockquote><blockquote>Andrew Hunt and David Thomas — The Pragmatic Programmer</blockquote><p>So I guess that’s it. Wish it useful :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29e45b38164e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/how-do-we-test-our-app-29e45b38164e">How we test our product</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement Django Watchman Custom Checks in NiceDay Backend]]></title>
            <link>https://medium.com/niceday-dev/implement-django-watchman-custom-checks-in-niceday-backend-640ccd322391?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/640ccd322391</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Ridwan Fajar]]></dc:creator>
            <pubDate>Sun, 12 Aug 2018 10:13:08 GMT</pubDate>
            <atom:updated>2018-08-15T11:42:30.258Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ElUZNEjMzw6iyyaFUZnstg.jpeg" /><figcaption>Pine Forests at Ciherang Village, Sumedang Regency, West Java, Indonesia</figcaption></figure><p>Around the end of last year, we started on a project to rebuild our backend. To build our new backend for our product <a href="http://niceday.app/">NiceDay</a> we decided to use Django, which is one of the most popular web frameworks in the Python community.</p><p>We used Django along with various Python packages to build our backend. For example, we use Django Watchman to identify whether our RDBMS is up or not. This feature is needed to monitor the status of all services which are required by our Django backend.</p><p>Watchman has capability to exposes a status endpoint for your backing services like databases, caches, etc. But its cannot check Redis or MongoDB, so technically we have to build the checkers by ourselves. On the other hand, Django Watchman itself provide us some information to build custom checkers like in this <a href="https://django-watchman.readthedocs.io/en/latest/readme.html#custom-checks"><strong>link</strong></a>. Here is sample snippet from documentation:</p><pre>from watchman.decorators import check</pre><pre><a href="http://twitter.com/check">@check</a><br>def my_check():<br>    return {&#39;x&#39;: 1}</pre><p>But at first glance, I couldn’t really understand what does that means. After I read thoroughly the documentation several times, I got the point from that section that we have to return anything as JSON and has a true value. Whenever a service was down, the JSON response from the custom checks will return improper JSON format. So at that point, we could get information that our service is getting a trouble.</p><h3>Implementation in our Backend</h3><p>Finally based on the documentation we build our custom checks to provide information about our service status. For example here is a snippet from our custom checks to assure that Redis is still up on our servers:</p><pre><br>from watchman.decorators import check<br>import redis<br>from django.conf import settings</pre><pre><a href="http://twitter.com/check">@check</a><br>def check_redis():<br>    r = redis.StrictRedis(<br>        host=settings.CHECK_REDIS_HOST,<br>        port=settings.CHECK_REDIS_PORT,<br>        db=settings.CHECK_REDIS_DB<br>    )</pre><pre>    r.set(&#39;foo&#39;, &#39;bar&#39;)<br>    r.ping()</pre><pre>    return {&quot;redis&quot;: {&quot;ok&quot;: True}}</pre><p>In this case we have a data that returned from <strong>check_redis()</strong>. If its response is not same with check_redis return on Watchman Dashboard, that indicates that our Redis is having some trouble.</p><p>Afterward, we try to attach the custom watchman checks to our Django <strong>settings.py</strong>:</p><pre>WATCHMAN_CHECKS = (<br>    ...,<br>    &#39;util.checks.check_redis&#39;,<br>)</pre><p>Finally, we could see the status of Redis instance via this Watchman Dashboard along with default checkers from Watchman:</p><pre>{<br>    databases: [<br>        {<br>            default: {<br>                ok: true<br>            }<br>        }<br>    ],<br>    redis: {<br>        ok: true<br>    },<br>    storage: {<br>        ok: true<br>    },<br>    caches: [<br>        {<br>            default: {<br>                ok: true<br>            }   <br>        }<br>    ]<br>}</pre><p>That’s it, we hope you can start to build your own watchman custom checkers in your backend system.</p><h3>References</h3><ul><li><a href="https://www.youtube.com/watch?v=iEgOCY7_zGI">Full-stack Django application monitoring with django-watchman (Michael Warkentin</a>)</li><li><a href="https://github.com/mwarkentin/django-watchman">Django Watchman Github Repo</a></li><li><a href="https://django-watchman.readthedocs.io/en/latest/">Django Watchman Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=640ccd322391" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/implement-django-watchman-custom-checks-in-niceday-backend-640ccd322391">Implement Django Watchman Custom Checks in NiceDay Backend</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Pull Requests with React Native]]></title>
            <link>https://medium.com/niceday-dev/testing-pull-requests-with-react-native-613cd10919f6?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/613cd10919f6</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Umar Nizamani]]></dc:creator>
            <pubDate>Thu, 26 Jul 2018 13:14:31 GMT</pubDate>
            <atom:updated>2018-07-26T13:29:03.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Early last year, we at <a href="https://www.sense-health.com/">Sense Health</a> decided to move all future mobile development to <a href="https://facebook.github.io/react-native/">React Native</a>. With a clear ambition to improve speed of development and iteration time, we saw that our team of skilled native developers coupled with a few solid front-end developers could speed up the development cycle by optimizing our workflow specifically for React Native development.</p><p>One of my favorite features of React Native is that almost the entire application logic lies in a JavaScript bundle. This means that all of the core code is interpreted on the fly and can be replaced over the air. During development this means extremely fast iterations; saving a file and reloading the app instantly uses the updated code. This allows rapid trial and error during development and removes the compile and wait time that native code comes introduce (Android has improved this with <a href="https://developer.android.com/studio/run/#instant-run">Instant Run</a> but there is still a long way to go to match the speed of RN development)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*nMliSenZorSYTiYQBbha9w.gif" /><figcaption>Source: <a href="https://github.com/NativeScript/NativeScript/issues/5447">https://github.com/NativeScript/NativeScript/issues/5447</a></figcaption></figure><p>The idea that the application logic is just a JavaScript bundle opens up a lot of new possibilities. One of the best utilization of this feature for deployments is <a href="https://github.com/Microsoft/react-native-code-push">CodePush</a>. CodePush allows you to deploy code updates and some assets over the air just like a website. This means no more waiting for app store reviews, just deploy the app through CodePush and when the user opens the app the JS bundle is updated in the background and the next time they open the app that annoying bug they were facing is fixed as long as the native code is not changed (Which is mostly the case for us)</p><p>With such amazing tooling in place, we never resisted the changes introduced by React Native and have went ahead to change our team structure and deployment processes to improve the development cycle as effectively as possible for our new application <a href="https://niceday.app/">NiceDay</a>.</p><p>Over the last year some amazing engineers at Sense Health have built an extremely efficient way of working on top of our existing CI, communication and project management tools. In our current workflow we build and deploy releases in <a href="https://travis-ci.org/">Travis</a> using <a href="https://fastlane.tools/">fastlane</a> and automatically deploy for different platforms (iOS/Android/CodePush) and stages (Alpha/Beta/Production). With automated scripts taking over the build steps, we have extended our CI workflow to announce releases on Slack for QA to start testing and showing the deployment status of each PR/Issue on Github to know whether its available in Alpha/Beta or Production. This also automatically moves all issues into `Deployed to Alpha/Beta/Production` lanes in our project management tool <a href="https://waffle.io/">Waffle</a>, giving a complete automated overview of every issue that is currently deployed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*bZvzg7YS6vPyP7oHvGP_xQ.jpeg" /><figcaption>Release flow for our app <a href="https://niceday.app/">NiceDay</a></figcaption></figure><p>Being a small team we have to be highly critical of the amount of time we spend and where we spend it and hence have been refining our process multiple times over the last year and are always looking at ways to make it even better.</p><p>Last week while having a brainstorming session with a colleague (<a href="https://twitter.com/freakinruben">Ruben Weijers,</a> who built the whole fastlane deployment pipeline!) to reduce time spent on code reviews, he shared how the team at <a href="https://artsy.github.io/blog/2018/03/17/two-years-of-react-native/#video">Artsy were testing Pull Requests</a> in their production application by adding a hidden Admin page. The idea is that if we can deploy code over the air for Alpha/Beta/Production, then we can do the same for Pull Requests and allow the user to select the PR in a hidden page to replace the current app bundle with the code in the latest commit for the PR.</p><p>That means every time there is a new commit for a PR, its built and deployed to CodePush and you can select the PR in the existing application to test the new commit and actually see how it looks!</p><p>I think this is a brilliant way to test PRs as this would save hours of developer time by allowing them to test PRs without building for iOS and Android each time they review code. Secondly, it can change the way PRs are tested completely specially for visual changes as now even the product owner and the designers can test the latest commit of each PR!</p><p>Building this is quite easy as CodePush supports a concept called <a href="https://github.com/Microsoft/react-native-code-push#dynamic-deployment-assignment">Dynamic Deployment Assignment.</a> The idea is that when an app starts it checks for updates via CodePush in its current deployment (i.e Alpha/Beta or Production) but we can make as many deployments as we want and can switch deployments at run-time. This means that production users can become beta testers on the fly.</p><p>When a user opts-in to become a beta tester, we ask CodePush to update the JS version of the app to the beta deployment which then overrides the current production JS code with the beta code and voila, we now have the latest beta features ready to test!</p><p>The same concept can be applied for PRs. If each PR is a different deployment we can just switch from the Alpha version of the app to any PR deployment and we would have the latest code for this PR.</p><p>To make this functional we only need to build 2 things:</p><p>1) We need to build the JS code and deploy it each time there is a commit to a PR, create a deployment stage in CodePush and then store the information somewhere</p><p>2) Add a debug menu to only the Alpha version of the app (for security reasons lets not allow this in any other version) and list all built PRs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*NDaQAIocwzvQuTjgtZU1GA.gif" /><figcaption>Pull Requests only visible for alpha users</figcaption></figure><p>Already having Travis and fastlane in place, I decided to just add a lane in fastlane to build the PR and create a new deployment key for new PRs. This information is then stored in Amazon S3. To run this lane, I added a new <a href="https://docs.travis-ci.com/user/build-stages/">build stage</a> in Travis to our existing configuration to run for all new PRs and commits to PRs.</p><p>Next in the application we would just retrieve all the data from S3 and display it in a list. When a user selects a PR, we then ask CodePush to switch the current deployment. This would then replace the app code from Alpha to the latest code in the specified PR deployment and voila you are ready to test.</p><p>As each PR is a deployment, similar to Alpha/Beta/Production, any time there is a new update the application is automatically updated. Which means whenever there is a new commit, the application updates itself in the background to the code from the latest commit!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*J6zbdebUJMXXgV3Lvej4kg.gif" /><figcaption>Switching to a PR in action!</figcaption></figure><p>It took less than 2 days of effort for prototyping, polishing and integrating the feature into our app and I can see this saving hours of work for each developer reviewing the PR as now they don’t need to manually build for iOS and Android to test PRs before accepting them and can just test it in the alpha version of the app on their phones.</p><p>Having just deployed this feature this week, I am curious to see how this feature is used by the team in the coming weeks and what new ideas come from the team to build an even more effective workflow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=613cd10919f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/testing-pull-requests-with-react-native-613cd10919f6">Testing Pull Requests with React Native</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revamping a legacy backend #3]]></title>
            <link>https://medium.com/niceday-dev/revamping-a-legacy-back-end-3-4cb0d39f7fdd?source=rss----33a6ea5ab6ed---4</link>
            <guid isPermaLink="false">https://medium.com/p/4cb0d39f7fdd</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[cto]]></category>
            <category><![CDATA[legacy-back-end]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Umar Nizamani]]></dc:creator>
            <pubDate>Thu, 26 Jul 2018 13:14:16 GMT</pubDate>
            <atom:updated>2018-07-27T08:14:29.177Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Going to Production</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tlIYMfo_H6xlvpeuvBjlOw.jpeg" /><figcaption>Cookie Production Line (Source: Unknown)</figcaption></figure><p>With an <a href="https://hackernoon.com/revamping-a-legacy-backend-1-1429a4ce77cb">infrastructure as code</a> for our server provisioning and a <a href="https://hackernoon.com/revamping-a-legacy-backend-2-56d6c98df1f3">containerized environment for our APIs</a> we are ready to migrate our production stack to the new container based setup. In this article I will explain our approach to production deployment and how we are ensuring high up-time of our legacy stack with minimal support.</p><p>Having tested our staging environment to be functional and being used for our deployments, we decided to do the final switch to production while minimizing down time.</p><p>Before we do the actual migration, we need to make sure we are alerted as soon as services go down or face any hiccups.</p><p><strong>Monitoring and Alerting</strong></p><p>For monitoring system health we have already been using <a href="https://prometheus.io/">Prometheus</a> for our existing stack. After deploying Rancher we added some metrics from Rancher to our Prometheus stack to ensure we could monitor service health from Prometheus.</p><p>Secondly we added alerts to our Prometheus stack by using <a href="https://prometheus.io/docs/alerting/alertmanager/">Alert Manager</a>. This allows us to create alerts based on different thresholds and operations on metrics collected by Prometheus. With each alert, we connect a severity rating ranging from Low (Disk Space &gt; 80%, CPU usage high on staging servers, etc) to Critical (Cluster down, Rancher Service down, etc).</p><p>These alerts are fed into our incident management tool, <a href="https://www.opsgenie.com/">OpsGenie</a> where we have an on-call schedule for the back-end team to ensure all incidents are resolved in a timely manner. This process has allowed us to avoid problems before they occur by reacting to potential upcoming issues before our users are affected and in an unfortunate scenario of a critical failure to be alerted the instance the service fails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/333/1*oPRuWWW11Fq0na7SajPNZw.gif" /><figcaption><strong>Time to deploy!</strong></figcaption></figure><p>Now that we have monitoring and alerting setup, we are ready to deploy to production! We initially mirrored all our services to a production rancher environment and ran stress tests for a few days to ensure everything was working as expected. After several days of testing and fine tuning our stack by re-deploying images multiple times a day we found and fixed several problems related to cleaning up dangling images, disk space issues due to oversized logs, etc and were now ready to do the final production switch over.</p><p>To ensure minimum downtime, we started by migrating a small amount of our traffic to one of the rancher servers from our DNS. After a day of successful production traffic handled by the Rancher cluster we decided to do the full switch over with load balancing on 3 Rancher agents while still keeping the legacy server running as a backup if things went wrong.</p><p>A month of testing with this setup gave us full confidence that our Rancher stack was fully functional and shut down the old server marking completion of this migration!</p><p><strong>Wohoo! Done with the legacy stuff, now we have a successful Docker based stack that should work flawless right?</strong></p><p>Well, almost. Even though now we have multiple fail overs and a well scaled setup, we are still working with legacy applications that were never designed with such a stack in mind.</p><p><strong>Configuration Hell</strong></p><p>In the first 2 months of production deployment, we had multiple incidents all of them primarily coming from incorrect configuration.</p><p>Its a well known problem that handling configurations in distributed environments can be quite painful as there are multiple copies of the service running on different servers and they all need to have the same configuration. To solve this, we coupled our application configurations with our server configurations in Ansible and ensured that all configurations have a single source of truth, i.e Ansible.</p><p>While this might not the best solution as it requires a strict following of process, i.e never edit configuration files manually on the server and there are better solutions out there e.g <a href="https://github.com/coreos/etcd">etcd</a> coupled with <a href="https://github.com/kelseyhightower/confd">confd</a> which can ensure configurations to be in a single place, it was important to identify the root of the problem before jumping into the solution.</p><p>The root of our problems were 2 folded:</p><ol><li><strong>Most of our applications loaded configurations from files only on boot-up</strong></li></ol><p>To explain why this is a bad practice for distributed systems, let me run you through a scenario.</p><p>Imagine you update all servers with changes to the configuration file from Ansible and re-start all services correctly. The server is running perfectly fine and everything is working as expected with the updated configuration.</p><p>Now a week later, someone from the ops team re-runs the Ansible playbook but in doing so, they accidentally run the Ansible playbook from a branch that does not contain the updated configuration file. When they deploy the incorrect configuration file to the server, the services running on this server aren’t affected as they loaded the configuration on boot-up and have the correct configuration in memory.</p><p>Now we are in an ugly situation of incorrect configuration on the server, but the correct configuration in memory and hence we are seeing no problems at this moment.</p><p>A week later, someone tries to release a new version of the application. At this moment the container has to be recreated with the new image and the incorrect configuration on the server is picked up by the application and the service starts failing.</p><p>This is causes the problem to be extremely nasty to debug. The developers are unaware whether their change caused the problem or not and the Dev Ops engineer who ran the Ansible playbook is completely unaware that their re-run caused the actual problem in the first place.</p><p>To solve this problem, instead of doing heavy changes to the code base itself (which could result in more problems due to it being a legacy code base), I added a one liner supervisor program that would restart the service whenever the configuration file was changed.</p><blockquote>command=bash -c “inotifywait -m -e modify /etc/service/service.conf | while read events; do supervisorctl restart SupervisorService; done”</blockquote><p>This means that as soon as someone runs the Ansible playbook with the incorrect configuration, the service is restarted effectively pulling the latest configuration and causing the service to fail if its in an incorrect configuration.</p><p>Note: This solution could be extended by adding etcd &amp; confd to avoid the problem created by running Ansible from an incorrect branch but to avoid spending more time then strictly required, we ensured that we only run Ansible playbooks for Rancher Agents from the Master branch.</p><p><strong>2. No checks for inter-service connections</strong></p><p>With our monitoring and alerting setup we are able to detect problems on servers and services as soon as they occur and with multiple nodes in each cluster our back-end is quite resilient to services going down.</p><p>Even though this gives us complete confidence on each node and service itself, we are still missing data on inter-service connections. This means that even though we know MySQL is up and we know our service is also up, it doesn’t mean everything is running as expected. It could be that somehow our connection to MySQL is broken (bad firewall rule, incorrect credentials, etc).</p><p>As we are working with legacy code that did not have distributed deployment in mind, our services have no concept of health checks.</p><p>To improve reliance and to increase confidence of our services, I decided to add a Health Check endpoint to all our services. Again to ensure minimal interaction with existing code (to avoid new problems from arising), I spent a week to make an endpoint in all our micro-services that returns 200 or 400 status code and returns a JSON object with the milli-seconds it took to get a response from each services it relies on.</p><p>An example of these tests would be to get a default user from MySQL, get values using RPC from another service, simple HTTP request to a third party service, etc. If all responses were successful, it would return a status 200 and otherwise return status 400.</p><p>This gives us an extremely easy way to debug if the system is working well and also to debug if any issues occur. An example of debugging issues, one day we suddenly faced create user requests timing out, the problem had never been faced before and would have taken a long time to debug as no-one knew why this was happening in the first place. With multiple micro-services working together and complex database relationships, this problem might have taken a very long time to debug but with the status end-point we instantly discovered that 1 micro-service was taking 30 seconds to respond to requests allowing us to identify and resolve the issue in record time.</p><p>This has been a huge learning experience for us converting a legacy back-end with a frail infrastructure to an extremely robust fail-safe cluster. Since the deployment of this setup, and applying the changes explained above, we have successfully crossed 3 months with 0 major incidents.</p><p>Did this help you migrate your legacy back-end to a fail safe environment? Drop a comment and let me know, I would love to hear your story :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cb0d39f7fdd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/niceday-dev/revamping-a-legacy-back-end-3-4cb0d39f7fdd">Revamping a legacy backend #3</a> was originally published in <a href="https://medium.com/niceday-dev">NiceDay Development</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>