<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Berk Gökden on Medium]]></title>
        <description><![CDATA[Stories by Berk Gökden on Medium]]></description>
        <link>https://medium.com/@berkgokden?source=rss-d1ef641932b6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uZHsjZjSy4zuu6aZrmxOeA.jpeg</url>
            <title>Stories by Berk Gökden on Medium</title>
            <link>https://medium.com/@berkgokden?source=rss-d1ef641932b6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:13:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@berkgokden/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Microservices Right: Clearing Up Common Mistakes and Misunderstandings]]></title>
            <link>https://medium.com/berk-gokden/getting-microservices-right-clearing-up-common-mistakes-and-misunderstandings-11fa93c29884?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/11fa93c29884</guid>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 19:41:38 GMT</pubDate>
            <atom:updated>2023-06-07T19:41:38.437Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*_2i9nQM2YCc3v8hVcU8bjQ.jpeg" /></figure><p>As an advocate for microservices, I feel it is essential to address some common mistakes that have led to recent pushback in the market. Microservices architecture has gained significant popularity in recent years due to its potential for scalability, agility, and fault isolation. However, certain misconceptions and missteps can hinder the successful implementation and adoption of microservices. In this article, we will explore these common mistakes and provide insights to help clarify the principles and best practices of microservices. I will try to be less technical and keep the discussion at the architectural level.</p><p><em>I plan to discuss several key points in microservices architecture development, although I won’t cover everything in this article. There are many aspects to consider in this field, and I look forward to delving into more detail in future posts.</em></p><p>Leveraging my extensive experience in implementing, troubleshooting, and consulting on microservices for numerous companies, I’ve noticed a recurring issue. Often, organizations tend to choose tools or technologies based on their popularity, rather than their applicability to the situation at hand.</p><p>As a seasoned expert, I’ve witnessed how decisions made in a hurry or without sufficient understanding can lead to complications later. For instance, a company may decide to use gRPC due to its quickness and efficiency. But if their team is more familiar with REST APIs, and their system is built around it, the gRPC implementation could become a bottleneck, slowing down the whole process.</p><p>Therefore, it’s crucial to assess technologies based on the company’s unique needs, current tech stack, and team’s know-how. If new technologies are under consideration, getting expert advice or training can prove highly advantageous. By adopting such mindful planning, organizations can sidestep common hurdles and truly harness the potential of microservices.</p><p><em>In the market, AWS Serverless, particularly AWS Lambda, is often used as an example when discussing microservices. However, it’s important to note that any problems or challenges faced with AWS Serverless should not be attributed to microservices as a whole. These issues are more likely related to specific implementation choices or limitations within the AWS Serverless platform itself. It should only be used for stateless, occasionally called, small services.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*PEjFt30A5N_lMB5dRJ-rDA.jpeg" /><figcaption>AWS Serverless is not always a good solution.</figcaption></figure><p><strong>Infrastructure:</strong></p><p>In my extensive work of implementing, troubleshooting, and advising on microservices for many companies, I’ve found that having a robust and well-managed infrastructure is a cornerstone of success. It’s like having a good foundation for a house — if it’s strong, everything you build on it will be more stable and effective. The right infrastructure makes it easier to add new services, manage loads effectively, spot problems quickly, measure performance, and alert the right people when something needs attention.</p><p>By setting up the right infrastructure from the start, companies can avoid many common problems, making their microservices more efficient, reliable, and easier to manage. This is a key point I always emphasize in my consulting work, because I’ve seen firsthand how much of a difference it can make.</p><p>This infrastructure should be able to handle scaling, logging, metrics, and alerting tasks. This way, each service doesn’t need to worry about these aspects and can focus on its own specific job.</p><p><strong>DevOps:</strong></p><p>In my experience guiding companies with microservices, the DevOps mindset is crucial. It allows developers to independently set up a service and a CI/CD pipeline within their sandbox in a few hours, following a straightforward guide. This self-sufficiency speeds up development, fosters system understanding, and improves teamwork. The result is a more robust and efficient microservice architecture. Combining this DevOps approach with solid infrastructure helps companies fully benefit from microservices.</p><p><strong>On Independent Code Repo Per Service:</strong></p><p>I advocate for maintaining mini independent code repositories instead of monorepos for each microservice. Services should avoid code dependencies on each other. This method keeps the code simple and allows for independent updates. It enables swift CI/CD and independent deployment. This approach helps to avoid code conflicts, which can slow down development in the future.</p><p><em>It’s unfortunate to see senior developers advocating for monorepos. They often justify this by pointing to large companies that use a single monorepo. However, this approach can result in slow and complicated development environments. While Google is known for using a monorepo, they have a unique file system and a dedicated DevOps team supporting it, which allows for separate folder updates, diverging from the true essence of a monorepo.</em></p><p><em>Simply because a method was used before DevOps came into the picture or because a successful company like Google uses it doesn’t make it the right choice for every situation. This misconception is a common problem in large companies and often leads to inefficiencies and complexities. Independent repositories for each service promote simpler code, faster CI/CD, and independent deployment, which are crucial for efficient microservices architecture.</em></p><p><strong>Responsibilities:</strong></p><p>Each service should have a dedicated owner. Leaving services unmaintained and ownerless is a frequent error. This also connects to another common error that including shared libraries with other services. Services should not carry extra code or libraries for logging or metrics, as these tasks should be handled by the infrastructure. Incorporating these operations into the service itself is a leftover practice from older times, contradicting modern DevOps principles. This makes updating and maintaining microservices an issue and also a liability in the future. It creates a wall to migrations.</p><p><strong>Size:</strong></p><p>The question of microservice size often comes up and I find it quite misguided. It seems like a relic from the Waterfall era. Although one could argue that a microservice should be small enough for a single developer to rewrite, this perspective isn’t entirely accurate. Service development isn’t static; the functionality of a service isn’t always defined from the start. Typically, you might begin by adding a new functionality to an existing service. As this functionality matures and expands, it may graduate and become a standalone service.</p><p><strong>Final thoughts:</strong></p><p>I was motivated to write this article because many companies struggle with effective microservice implementation. This often results in slower development, increased costs, never-ending migrations, and even developers leaving the company. It’s disheartening to see senior developers and managers sometimes make poor decisions. For example, developers might attempt to implement a microservice without the right infrastructure, leading to issues down the line.</p><p>With current tools like Kubernetes as a service, load balancers, reverse proxies, managed code repositories, and infrastructure as a service, setting up a microservices infrastructure is achievable without excessive cost. An experienced engineer can easily navigate these technologies. If you’re unsure or need guidance, just reach out to an expert in the field.</p><p>I hope this article has provided some valuable insights for you. Should you have any comments or queries, don’t hesitate to leave a comment or connect with me directly on LinkedIn. I’m always eager to engage in meaningful discussions on this topic. Additionally, if you’re seeking professional assistance, I offer services to help restructure your architecture and provide recommendations on strategic decisions. I look forward to hearing from you.</p><p>My Linkedin: <a href="https://www.linkedin.com/in/berkgokden/">https://www.linkedin.com/in/berkgokden/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11fa93c29884" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/getting-microservices-right-clearing-up-common-mistakes-and-misunderstandings-11fa93c29884">Getting Microservices Right: Clearing Up Common Mistakes and Misunderstandings</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[That Kubernetes And Friends Stack]]></title>
            <link>https://medium.com/berk-gokden/that-kubernetes-and-friends-stack-d49598f8318c?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d49598f8318c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 07:37:32 GMT</pubDate>
            <atom:updated>2020-07-02T14:43:22.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*ylQQ6beZwan5biID57mVCw.png" /></figure><p>I wanted to write a post about Continuous Delivery pipelines but you will end up with a <a href="https://kubernetes.io/">Kubernetes</a> Stack anyway so I will write this post oriented around Kubernetes and friends. <strong>The hardest part of Kubernetes is deciding on your stack so I am here to give you a good starting point.</strong></p><p>Before starting this post make sure that your Continues Integration Pipeline is in place and your images are pushed to a docker repository and they are semantically versioned.</p><blockquote><strong>Our aim is to have a common, mostly provider-independent easy to use infrastructure that everyone can understand.</strong></blockquote><p>There may be variations based on your cloud provider but the main points of our stack will be like this:</p><p><a href="https://hub.docker.com/">Docker Hub</a> + <a href="https://kubernetes.io/">Kubernetes</a> + <a href="https://www.weave.works/docs/net/latest/kubernetes/kube-addon/">Weave Net</a>+ <a href="https://kubernetes.github.io/ingress-nginx/deploy/">Nginx</a> + <a href="https://prometheus.io/">Prometheus</a>+<a href="https://grafana.com/">Grafana</a> + <a href="https://www.fluentd.org/">Fluentd</a>+ <a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-quickstart.html">ElasticSearch</a> +<a href="https://www.elastic.co/kibana">Kibana</a>+ <a href="https://argoproj.github.io/argo-cd/">ArgoCD</a> + <a href="https://helm.sh/">Helm 3</a> + <a href="https://github.com/">Github</a> + <a href="https://circleci.com/">CircleCI</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*boHmV2QhWT6JdkmKEfpo5w.jpeg" /></figure><p><a href="https://hub.docker.com/">Docker Hub</a> is our docker image registry. You can use <a href="https://aws.amazon.com/ecr/">AWS ECR</a> or GCP Container Registry based on your cloud provider. I urge you to share your public images in Docker Hub which is default and easy to reach by developers. Some private container registries have tricks to make it work with a Kubernetes like periodically updating the image pull secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*VhcKLxiPGZEj9U2Tf25svQ.png" /><figcaption><a href="https://itnext.io/kubernetes-journey-up-and-running-out-of-the-cloud-introduction-f04a811c92a5">https://itnext.io/kubernetes-journey-up-and-running-out-of-the-cloud-introduction-f04a811c92a5</a></figcaption></figure><p><a href="https://kubernetes.io/">Kubernetes</a> is a production-grade container orchestration platform. It is a battle-tested and commonly used platform currently. Please use a managed Kubernetes cluster if you are not a Kubernetes provider or a large company that has enough employees to keep people on-call, all the time. There are very good providers right now. Almost all big providers (<a href="https://aws.amazon.com/eks/">AWS</a>, <a href="https://cloud.google.com/kubernetes-engine">GCP</a>, <a href="https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes#:~:text=Azure%20Kubernetes%20Service%20(AKS)%20makes,managed%20Kubernetes%20cluster%20in%20Azure.&amp;text=Additional%20features%20such%20as%20advanced,containers%20are%20supported%20in%20AKS.">Azure</a>) are in a good state and provide a decent solution (<a href="https://aws.amazon.com/eks/">EKS</a>, <a href="https://cloud.google.com/kubernetes-engine">GKE</a>, <a href="https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes#:~:text=Azure%20Kubernetes%20Service%20(AKS)%20makes,managed%20Kubernetes%20cluster%20in%20Azure.&amp;text=Additional%20features%20such%20as%20advanced,containers%20are%20supported%20in%20AKS.">AKS</a>,…). In my experience, GCP is the best for Kubernetes but most people are AWS fanatics. Also, to keep costs low, you can use spot instances in AWS and reserved instances in GCP so your costs will be lower compared to a similar solution with EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*kS7wB5VeeSl5tWKwtNKUOw.png" /></figure><p><a href="https://www.weave.works/docs/net/latest/kubernetes/kube-addon/">Weave Net</a> from Weave works as a networking driver. Weave Net also has support to encrypt your network so you will be safer while developing applications on your network. This is a serious issue, depending on your business there are regulations about it. Encrypt your network and data on rest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDFEDcaNXOHWE7NQSlzJ7Q.png" /></figure><p><a href="https://kubernetes.github.io/ingress-nginx/deploy/">Nginx</a> is a reverse proxy and it has a pretty commonly used ingress controller and API Gateway for Kubernetes. It is really easy to use if you don’t know what to use Nginx. Depending on your requirements you can move to <a href="https://www.haproxy.com/documentation/hapee/1-9r1/installation/kubernetes-ingress-controller/">HaProxy</a>, <a href="https://docs.traefik.io/">Traefik</a>, <a href="https://istio.io/">ISTIO</a>, <a href="https://www.getambassador.io/">Ambassador</a>, <a href="https://www.envoyproxy.io/">Envoy</a>, or <a href="https://konghq.com/">Kong</a>. You can start with Nginx in a couple of minutes and there are enough documentation and support in the public domain. ISTIO has the most complete solution and also supports Mutual TLS for internal communication but it is a bit harder to work with. I have been working with ISTIO since version 0.5, it has evolved to be a nice solution but you may need an expert to make it work for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZuwH3hbhj0kTLUnxrJ2Mg.png" /></figure><p><a href="https://prometheus.io/">Prometheus</a> is for metrics gathering. It has a standard API and supported by many programming languages. You can view metrics with <a href="https://grafana.com/">Grafana</a> but as a software developer, I use Prometheus API to build other products over it. You can build A/B testing, performance optimization, canary releasing, anomaly detection based on metrics stored in Prometheus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*XC6k_BN8KE8QFQvwrWt3gw.png" /></figure><p><a href="https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-quickstart.html">ElasticSearch</a> is for storing logs. ElasticSearch can do lots of things but it is a text search engine. I see many companies trying to use it as a metrics engine and failing miserably. ElasticSearch can be installed in your cluster with <a href="https://www.fluentd.org/">Fluentd</a> or <a href="https://fluentbit.io/">FluentBit</a> to gather logs of your containers. It is a very common solution. You can use Kibana to visualize the data stored in ElasticSearch. Also, you may need to write a job to delete old indexes periodically, the free version still doesn’t support the index lifecycle. I recommend you to use a hosted ElasticSearch if you are not insane. When you need the see the logs, it is because something went wrong with your cluster and the same problem may affect your ElasticSearch if your ElasticSearch is running in the same cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DT_UotBwRQxbeIoCqYpurg.png" /></figure><p><a href="https://argoproj.github.io/argo-cd/">ArgoCD</a> is very new on my list. It is used for Infrastructure as Code pattern. Where you install ArgoCD controller in our cluster and keep cluster definition in Git and it automatically syncs our container state with the Git. There are two popular solutions <a href="https://fluxcd.io/">FluxCD</a> and ArgoCD. FluxCD is a more simple solution targeting an automated environment. ArgoCD has UI and targeting more complex companies. Probably you will use <a href="https://github.com/">Github</a> as your Git solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*rOHoVr3qjOdqIbE90tySOA.jpeg" /></figure><p><a href="https://helm.sh/">Helm 3</a> is for templating your YAML definitions and it is very common. And use helm 3, not helm 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*2TUHWGDQ8A8Z_nHwzsBYmQ.png" /></figure><p><a href="https://circleci.com/">CircleCI</a> is for the CI pipeline. It is really easy to use but you may go with other solutions but it has enough features and works well. You can use a CI flow to update the Infrastructure Code as the last stage of your CI pipeline which will start the CD pipeline. You can also write some periodic control tasks for your clusters.</p><p>There are other components and controllers that you may need like <a href="https://cert-manager.io/docs/">Cert Manager</a>, <a href="https://github.com/kubernetes-sigs/external-dns">External DNS</a>. They are easy to integrate after adding these main components.</p><p>I hope this will give a good starting point for your Kubernetes Cluster.</p><p>Go run your own!</p><p>Follow me on <a href="https://github.com/bgokden">Github</a> or <a href="https://www.linkedin.com/in/berkgokden/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49598f8318c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/that-kubernetes-and-friends-stack-d49598f8318c">That Kubernetes And Friends Stack</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Anomaly Detection with Autoencoders to Fraud Detection]]></title>
            <link>https://medium.com/data-science/applying-anomaly-detection-with-autoencoders-to-fraud-detection-feaaee6b5b09?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/feaaee6b5b09</guid>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[anomaly-detection]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[fraud-detection]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Mon, 08 Jun 2020 06:01:01 GMT</pubDate>
            <atom:updated>2020-06-21T19:41:24.761Z</atom:updated>
            <content:encoded><![CDATA[<h4>Credit card fraud can be classified as an anomaly and using autoencoders implemented in Keras it is possible to detect fraud</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Hx5HxasUCM4F_Da32coQA.jpeg" /><figcaption><a href="https://unsplash.com/photos/TFqKR4Ynjm8">https://unsplash.com/photos/TFqKR4Ynjm8</a></figcaption></figure><p>I recently read an article called <a href="https://medium.com/swlh/anomaly-detection-with-autoencoders-2bd23dedbd9e">Anomaly Detection with Autoencoders</a>. The article was based on generated data, so it sounded like a good idea to apply this idea to a real-world fraud detection task and validate it.</p><p>I decided to use <a href="https://www.kaggle.com/mlg-ulb/creditcardfraud">Credit Card Fraud Dataset From Kaggle</a>*:</p><blockquote>The datasets contains transactions made by credit cards in September 2013 by european cardholders.<br>This dataset presents transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.</blockquote><p>It is a very unbalanced dataset and a good candidate to identify fraud through anomalies.</p><p><strong>Let’s start with data discovery:</strong></p><p>We are going to do a smaller plot after decreasing our dimensions from 30 to 3 with <a href="https://en.wikipedia.org/wiki/Principal_component_analysis">Principal Component Analysis</a>. This data has 32 columns where the first column is the time index, 29 unknown features, 1 transaction amount, and 1 class. I will ignore the time index since it is not stationary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2e496ebd851f37a6a473d33edd38107/href">https://medium.com/media/c2e496ebd851f37a6a473d33edd38107/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NfXaAx49UZCFj9e1g3hYOA.png" /></figure><p>Your first reaction could be that there are two clusters and this would be an easy task but fraud data is yellow points! There are three visible yellow points in the large cluster. So let’s subsample the normal data while keeping the number of fraud data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9b2679c16099fbeea26864764b8005f/href">https://medium.com/media/d9b2679c16099fbeea26864764b8005f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Iddlxd2aXHSdqT2g3o65aQ.png" /></figure><p>Now it is visible that normal transactions are clustered in a disk while frauded transactions are more distributed.</p><p>We are going to build an autoencoder with 3 layer encoder and 2 layer decoder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*fmfV24QYGa9_P5CKVTVotA.png" /><figcaption><a href="https://medium.com/swlh/anomaly-detection-with-autoencoders-2bd23dedbd9e">https://medium.com/swlh/anomaly-detection-with-autoencoders-2bd23dedbd9e</a></figcaption></figure><p>The <a href="https://blog.keras.io/building-autoencoders-in-keras.html">Autoencoder</a> will encode our data into a subspace and decode the feature back while <em>normalizing</em> the data. Our expectation is autoencoder will learn the features of normal transactions and the input will be similar to output when applied. For anomalies, the input and the output will be significantly different since it is unexpected data.</p><p>The good part of this approach is it allows us to use <strong>unsupervised learning</strong> and we usually have plenty of normal transaction data. Data labeling is usually expensive, hard, and in some cases unavailable. Manual data labeling also includes human interaction which causes human biased implementations. It can be seen that in the model training we only use normal transaction features and not the labels.</p><p>Let’s load data and train our autoencoder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd0e662558b5f48e3ec404e90af40121/href">https://medium.com/media/bd0e662558b5f48e3ec404e90af40121/href</a></iframe><p>My model settles around validation loss of 8.5641e-04. (It can go as low as 5.4856e-04.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*oGMA08Zs78Edu4tbyEVCTg.png" /></figure><p>Using this model, we will calculate the mean squared error (mse) for normal transactions and calculate a threshold value which is 95 percentile of all mse values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eea1f6fcdf1350fe7d94a66520daaa18/href">https://medium.com/media/eea1f6fcdf1350fe7d94a66520daaa18/href</a></iframe><p>We found our threshold (cut_off) as 0.002. We will consider a transaction as an anomaly if the mean squared error is higher than 0.002. Let’s select 100 fraud samples and 100 normal samples and plot it against the threshold:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c87fc2acfc90e54899dd2d70f5d39e1/href">https://medium.com/media/2c87fc2acfc90e54899dd2d70f5d39e1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ofC48lWn_HCoH_YpAueZAA.png" /></figure><p>It is visible that most of the fraudulent transactions have high mean squared errors compared to normal transactions. It looks very promising.</p><p>We gave up on 5% of the normal transactions. There are still fraud transactions that are below the threshold. This can potentially be improved by using better feature extraction since it seems like some fraud data has very similar features to normal transactions. Some valuable features for credit card fraud are the number of transactions in the previous hour/day/week, if the transaction initiated in a different country than the issued country.</p><p><strong>Future tasks:</strong></p><ul><li>Use a better model by using hyperparameter optimization.</li><li>Analyze the data to understand the features.</li><li>Compare these results to a common approach like SVM or K-means clustering.</li></ul><p>Full code for this post can be found on Github:</p><p><a href="https://github.com/bgokden/anomaly-detection-with-autoencoders">bgokden/anomaly-detection-with-autoencoders</a></p><p>Follow me on Github and Linkedin:</p><p><a href="https://www.linkedin.com/in/berkgokden/">Berk Gökden - Senior Software Engineer - Caspar.AI | LinkedIn</a></p><h3>*Acknowledgements For Credit Fraud Dataset</h3><p>The dataset has been collected and analysed during a research collaboration of Worldline and the Machine Learning Group (<a href="http://mlg.ulb.ac.be/">http://mlg.ulb.ac.be</a>) of ULB (Université Libre de Bruxelles) on big data mining and fraud detection.<br>More details on current and past projects on related topics are available on <a href="https://www.researchgate.net/project/Fraud-detection-5">https://www.researchgate.net/project/Fraud-detection-5</a> and the page of the <a href="https://mlg.ulb.ac.be/wordpress/portfolio_page/defeatfraud-assessment-and-validation-of-deep-feature-engineering-and-learning-solutions-for-fraud-detection/">DefeatFraud</a> project</p><p>Cited works:</p><p>Andrea Dal Pozzolo, Olivier Caelen, Reid A. Johnson and Gianluca Bontempi. <a href="https://www.researchgate.net/publication/283349138_Calibrating_Probability_with_Undersampling_for_Unbalanced_Classification">Calibrating Probability with Undersampling for Unbalanced Classification.</a> In Symposium on Computational Intelligence and Data Mining (CIDM), IEEE, 2015</p><p>Dal Pozzolo, Andrea; Caelen, Olivier; Le Borgne, Yann-Ael; Waterschoot, Serge; Bontempi, Gianluca. <a href="https://www.researchgate.net/publication/260837261_Learned_lessons_in_credit_card_fraud_detection_from_a_practitioner_perspective">Learned lessons in credit card fraud detection from a practitioner perspective</a>, Expert systems with applications,41,10,4915–4928,2014, Pergamon</p><p>Dal Pozzolo, Andrea; Boracchi, Giacomo; Caelen, Olivier; Alippi, Cesare; Bontempi, Gianluca. <a href="https://www.researchgate.net/publication/319867396_Credit_Card_Fraud_Detection_A_Realistic_Modeling_and_a_Novel_Learning_Strategy">Credit card fraud detection: a realistic modeling and a novel learning strategy,</a> IEEE transactions on neural networks and learning systems,29,8,3784–3797,2018,IEEE</p><p>Dal Pozzolo, Andrea <a href="http://di.ulb.ac.be/map/adalpozz/pdf/Dalpozzolo2015PhD.pdf">Adaptive Machine learning for credit card fraud detection</a> ULB MLG PhD thesis (supervised by G. Bontempi)</p><p>Carcillo, Fabrizio; Dal Pozzolo, Andrea; Le Borgne, Yann-Aël; Caelen, Olivier; Mazzer, Yannis; Bontempi, Gianluca. <a href="https://www.researchgate.net/publication/319616537_SCARFF_a_Scalable_Framework_for_Streaming_Credit_Card_Fraud_Detection_with_Spark">Scarff: a scalable framework for streaming credit card fraud detection with Spark</a>, Information fusion,41, 182–194,2018,Elsevier</p><p>Carcillo, Fabrizio; Le Borgne, Yann-Aël; Caelen, Olivier; Bontempi, Gianluca. <a href="https://www.researchgate.net/publication/332180999_Deep-Learning_Domain_Adaptation_Techniques_for_Credit_Cards_Fraud_Detection">Streaming active learning strategies for real-life credit card fraud detection: assessment and visualization,</a> International Journal of Data Science and Analytics, 5,4,285–300,2018,Springer International Publishing</p><p>Bertrand Lebichot, Yann-Aël Le Borgne, Liyun He, Frederic Oblé, Gianluca Bontempi <a href="https://www.researchgate.net/publication/332180999_Deep-Learning_Domain_Adaptation_Techniques_for_Credit_Cards_Fraud_Detection">Deep-Learning Domain Adaptation Techniques for Credit Cards Fraud Detection</a>, INNSBDDL 2019: Recent Advances in Big Data and Deep Learning, pp 78–88, 2019</p><p>Fabrizio Carcillo, Yann-Aël Le Borgne, Olivier Caelen, Frederic Oblé, Gianluca Bontempi <a href="https://www.researchgate.net/publication/333143698_Combining_Unsupervised_and_Supervised_Learning_in_Credit_Card_Fraud_Detection">Combining Unsupervised and Supervised Learning in Credit Card Fraud Detection </a>Information Sciences, 2019</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=feaaee6b5b09" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/applying-anomaly-detection-with-autoencoders-to-fraud-detection-feaaee6b5b09">Applying Anomaly Detection with Autoencoders to Fraud Detection</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[API First Approach with OpenAPI 3 and REST — Practical Software Development Part 3]]></title>
            <link>https://medium.com/berk-gokden/api-first-approach-with-openapi-3-and-rest-practical-software-development-part-3-60f95d35e3b9?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/60f95d35e3b9</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[open-api]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 08:04:08 GMT</pubDate>
            <atom:updated>2020-06-02T08:04:08.997Z</atom:updated>
            <content:encoded><![CDATA[<h3>API First Approach with OpenAPI 3 and REST — Practical Software Development Part 3</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPQoOYO5hjvs97yFqRdxOg.png" /></figure><p>Both Service-oriented architecture and microservices require well defined and documented APIs. Microservices is a subset of Service Oriented Architecture where we split our services into smaller isolated parts. The idea is smaller parts are easy to develop and faster to iterate. As I explained in <a href="https://blog.berkgokden.com/practical-rules-for-software-development-part-1-e082378ce332">my previous post</a>, a microservice should be able to re-written in less than a sprint given the specifications.</p><p>The first problem is how to define a standard, well-documented API Specification that you can iterate over. Luckily there is already a commonly used standard: <a href="https://www.openapis.org/">OpenAPI Specification</a> formerly known as <a href="https://swagger.io/specification/">Swagger Specification</a>. Swagger has years of experience in the API development field and with the support of Mulesoft, OpenAPI 3 has support and integration to <a href="https://raml.org/">RAML</a> (RESTful API Modeling Language).</p><p>I recommend you to follow <a href="https://grpc.io/">gRPC</a> for internal services. For external services or services that require edge caching, the read-write separation you should use REST APIs.</p><p>OpenAPI Specification allows you to define, your API, Authentication methods, Access control definitions, documentation, and service details in one place and gives you tools to generate code and documentation.</p><p>In this post, we will build a small service starting with the API and generate its code, documentation, and build a quick prototype.</p><p>Let’s assume that our product manager wants a widget on our website that shows popular movies and let the user see some details about them. So you need to come up with an API discussing with Stakeholders which are product manager and frontend developers in this case.</p><p>We will build a service caches popular movies and short information about them using <a href="https://www.themoviedb.org/">The Movie Database</a> API. This is a very simple service that lists popular movies and also allows you to query individual movies. Sometimes, we add services to cache external API calls since they are limited, we don’t want to do external API calls frequently and we don’t want to share our API key publicly.</p><p>We had a meeting, negotiated with stakeholders, and come up with this API specification:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d92a86f64d43c7ca1a225f6d787e62f3/href">https://medium.com/media/d92a86f64d43c7ca1a225f6d787e62f3/href</a></iframe><p>This is a very simple spec with 2 API calls and no authentication.<br>You can keep this API definition in a common repository or on the server-side as the source of truth. This specification allows you to generate both client and server-side code so it would be better to keep them in a common repository.</p><p>The second problem is how to implement this API as it is defined in the specification without too much hustle.</p><p>For this purpose, we will use <a href="https://openapi-generator.tech/">openapi-generator</a> developed by Swagger. You can install the way you prefer, I use brew for MacOS:</p><pre>brew install openapi-generator</pre><p>We will generate go server code from the API spec inside a project folder movielist which also includes standard files like Dockerfile, and README. Use the following command to generate the project:</p><pre>openapi-generator generate -i https://gist.githubusercontent.com/bgokden/031400fc7d073c0762b7ed595e81eb68/raw/56097eb7fe844469a2e4066e2d4b93dd5c868a30/example_open_api_3_api_spec.yaml -g go-server -o movielist</pre><p>As a developer, we don’t like to write documentation much, personally I like to keep documentation next to the code to keep it in sync so we will generate markdown documentation from the API spec in the project folder:</p><pre>openapi-generator generate -i https://gist.githubusercontent.com/bgokden/031400fc7d073c0762b7ed595e81eb68/raw/56097eb7fe844469a2e4066e2d4b93dd5c868a30/example_open_api_3_api_spec.yaml -g markdown -o movielist</pre><p>Check the project folder, you will have a project structure as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sIumtmcVlzoWBszSmu4Vfw.png" /></figure><p>A multistage Dockerfile is in the project root.<br>A Readme is available with basic documentation in the project root.<br>Most of the source code is under the ‘go’ folder.<br>Markdown documentation is under the ‘Apis’ folder.<br>A copy of the OpenApi Specification is under the ‘api’ folder</p><p>There can be some small problems in the generated code like I had an unused import. After removing it, I can already run:</p><pre>go run main.go</pre><p>And you will have a service with the defined API exposed on port 8080.</p><p>All the logic we need to implement is inside ‘go/api_movie_service.go’</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54edbe06f40b93bc56b0e956770604f6/href">https://medium.com/media/54edbe06f40b93bc56b0e956770604f6/href</a></iframe><p>We are going to add another file called `moviedb.go` under ‘go’ folder and implement all the logic there.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef635b5aec39cef0450bcb2267b2ec7a/href">https://medium.com/media/ef635b5aec39cef0450bcb2267b2ec7a/href</a></iframe><p>The file ‘moviedb.go’ uses a loading cache to store the list of popular movies and movie information. Now bind this methods to the API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/716decc120c4df291ee86ee72811934b/href">https://medium.com/media/716decc120c4df291ee86ee72811934b/href</a></iframe><p>Only two lines needed to be changed to call the logic.</p><p>Export your API KEY from <a href="https://www.themoviedb.org/">The Movie Database</a> or use the one embedded in the code. Normally you should not embed credentials in code.</p><p>And run:</p><pre>go run main.go</pre><p>Check your endpoint with curl.<br>List popular movies:</p><pre>$ curl localhost:8080/v1/movies<br>[{&quot;id&quot;:419704,&quot;title&quot;:&quot;Ad Astra&quot;},{&quot;id&quot;:338762,&quot;title&quot;:&quot;Bloodshot&quot;},{&quot;id&quot;:454626,&quot;title&quot;:&quot;Sonic the Hedgehog&quot;},{&quot;id&quot;:38700,&quot;title&quot;:&quot;Bad Boys for Life&quot;},{&quot;id&quot;:385103,&quot;title&quot;:&quot;Scoob!&quot;},<br>{&quot;id&quot;:475557,&quot;title&quot;:&quot;Joker&quot;},{&quot;id&quot;:576156,&quot;title&quot;:&quot;The Lovebirds&quot;},{&quot;id&quot;:495764,&quot;title&quot;:&quot;Birds of Prey (and the Fantabulous Emancipation of One Harley Quinn)&quot;},{&quot;id&quot;:530915,&quot;title&quot;:&quot;<br>1917&quot;},{&quot;id&quot;:920,&quot;title&quot;:&quot;Cars&quot;},{&quot;id&quot;:686245,&quot;title&quot;:&quot;Survive the Night&quot;},{&quot;id&quot;:496243,&quot;title&quot;:&quot;Parasite&quot;},{&quot;id&quot;:545609,&quot;title&quot;:&quot;Extraction&quot;},{&quot;id&quot;:330457,&quot;title&quot;:&quot;Frozen II&quot;},{&quot;id&quot;:<br>508439,&quot;title&quot;:&quot;Onward&quot;},{&quot;id&quot;:420817,&quot;title&quot;:&quot;Aladdin&quot;},{&quot;id&quot;:181812,&quot;title&quot;:&quot;Star Wars: The Rise of Skywalker&quot;},{&quot;id&quot;:443791,&quot;title&quot;:&quot;Underwater&quot;},{&quot;id&quot;:210577,&quot;title&quot;:&quot;Gone Girl&quot;},<br>{&quot;id&quot;:568160,&quot;title&quot;:&quot;Weathering with You&quot;}]</pre><p>Get one movie:</p><pre>$ curl localhost:8080/v1/movie/420817<br>{&quot;id&quot;:420817,&quot;title&quot;:&quot;Aladdin&quot;,&quot;release_date&quot;:&quot;2019-05-22&quot;,&quot;original_language&quot;:&quot;en&quot;,&quot;poster_path&quot;:&quot;/3iYQTLGoy7QnjcUYRJy4YrAgGvp.jpg&quot;,&quot;overview&quot;:&quot;A kindhearted street urchin named Alad<br>din embarks on a magical adventure after finding a lamp that releases a wisecracking genie while a power-hungry Grand Vizier vies for the same lamp that has the power to make their de<br>epest wishes come true.&quot;,&quot;vote_average&quot;:7.1}</pre><p>There is a Dockerfile in the project but I will use my own<a href="https://blog.berkgokden.com/continuous-integration-practices-with-docker-part-2-3573da77a9d8"> ‘nicer’ Dockerfile for Golang services</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbc8026e300520f843aa5e85113cd9be/href">https://medium.com/media/dbc8026e300520f843aa5e85113cd9be/href</a></iframe><p>Copy-paste this over the existing Dockerfile and build your docker image with:</p><pre>docker build -t movielist .</pre><p>And run it locally with:</p><pre>docker run -p 8080:8080 movielist</pre><p>Finally, you can find all the project code mentioned here on GitHub:</p><p><a href="https://github.com/bgokden/movielist">bgokden/movielist</a></p><p>When you check the Github Repo, you will realize the root Readme has documentation and references to the API and Model documentation. I did this for simplicity. You can put it under a separate docs folder while generation.</p><p>You can also generate client code in other languages so frontend developers can just import the generated code and start using the client.</p><p>In this post, I wanted to explain that code generation based on API should be automated and standardized. Developers sometimes spend too much time on these tasks which are pretty boring and straightforward. It is sad for me to see a developer team trying to set up just the API for weeks, adding documentation tasks that are actually never completed because it needs to be updated every sprint.</p><p>Follow me on Github and Linkedin:</p><p><a href="https://www.linkedin.com/in/berkgokden/">Berk Gökden - Senior Software Engineer - Caspar.AI | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60f95d35e3b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/api-first-approach-with-openapi-3-and-rest-practical-software-development-part-3-60f95d35e3b9">API First Approach with OpenAPI 3 and REST — Practical Software Development Part 3</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Integration Practices with  Docker— Part 2]]></title>
            <link>https://medium.com/berk-gokden/continuous-integration-practices-with-docker-part-2-3573da77a9d8?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3573da77a9d8</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Thu, 28 May 2020 06:31:00 GMT</pubDate>
            <atom:updated>2020-05-28T06:31:00.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>Continuous Integration Practices with Docker— Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*kTpnKjR80SbAUtGtBGGLlg.png" /></figure><p>This is part 2 of my previous blog post on <a href="https://blog.berkgokden.com/practical-rules-for-software-development-part-1-e082378ce332">practical software development principles.</a></p><p>There are so many docker file examples online but they don’t go into detail or don’t give all best practices at once. Many developers use default tools made by the language’s build tool or generic docker images. Most of the developers just build their code and copy into a generic image and unfortunately, they think it is the right way since there is no quality control.</p><p><strong>Use Docker, not just for distributing your application but also for standardizing your continuous delivery pipeline.</strong></p><p>In <a href="https://blog.berkgokden.com/practical-rules-for-software-development-part-1-e082378ce332">my previous article</a>, I mentioned that every developer should be able to build, test, and debug locally. This is also true for your Continuous Delivery platform: a developer should be able to run the same test and build infrastructure locally. “<em>Tests pass on my computer but not on CI</em>” is another version of “<em>it works on my computer</em>”. Often CI platform has a different architecture, less CPU/RAM. It is very common that tests depend on timeouts and it fails on CI because it runs slower. Sometimes there is a dependency you had on your computer but forgot about it. It is a good practice to agree that your tests and builds should be able to run inside a docker container and a developer who joins the team should be able to run it with just reading README and having docker-desktop installed. This will decrease the onboarding of a new developer significantly.</p><p>I will explain this article over an example Golang application since it is a compiled language and more standardized.</p><p>Before reading this you may also want to check <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/">Dockerfile Best Practices on the official docker page</a>. I will stress on specific parts and how to achieve it.</p><p>These are the best practices that I will stress:</p><ul><li>Use Multistage builds to split build and runtime image.</li><li>Make your final image as small as possible.</li><li>Run only one process in one docker container.</li><li>Run as a non-root user.</li></ul><p><strong>Use Multistage builds to split build and runtime image.</strong></p><p>It is a very common and good practice to split your build and runtime image.</p><p>This is <a href="https://docs.docker.com/develop/develop-images/multistage-build/#name-your-build-stages">a multistage example from official docker page</a>:</p><pre>FROM golang:1.7.3 AS builder<br>WORKDIR /go/src/github.com/alexellis/href-counter/<br>RUN go get -d -v golang.org/x/net/html  <br>COPY app.go    .<br>RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .<br><br>FROM alpine:latest  <br>RUN apk --no-cache add ca-certificates<br>WORKDIR /root/<br>COPY --from=builder /go/src/github.com/alexellis/href-counter/app .<br>CMD [&quot;./app&quot;]</pre><p>The first stage named “builder” has the Golang compiler, installs dependencies, and based on Debian. It includes common tools like bash, curl that should not be included in a production image.</p><p><strong>Let’s concentrate on the builder:</strong></p><p>Our main idea is to have a standard build image with best practices that everyone can run.</p><p>We are going to build our first stage image in a totally different repository where we install commonly used libraries and tools.</p><pre># golang debian buster 1.14.1 linux/amd64<br># <a href="https://github.com/docker-library/golang/blob/master/1.14/buster/Dockerfile">https://github.com/docker-library/golang/blob/master/1.14/buster/Dockerfile</a><br>FROM golang@sha256:eee8c0a92bc950ecb20d2dffe46546da12147e3146f1b4ed55072c10cacf4f4c as builder</pre><pre># Ensure ca-certficates are up to date<br>RUN update-ca-certificates</pre><pre>WORKDIR /tmp/app</pre><pre># use modules<br>COPY go.mod tools.go /tmp/app/</pre><pre>ENV GO111MODULE=on<br>RUN go mod tidy<br>RUN go mod download<br>RUN go mod verify</pre><pre>RUN go get github.com/mattn/goveralls</pre><pre>RUN rm -rf /tmp/app</pre><pre>ONBUILD RUN update-ca-certificates</pre><pre>ONBUILD COPY . .</pre><pre>ONBUILD RUN go test -v -cover -race -coverprofile=./coverage.out ./...</pre><pre># Enforce code coverage check</pre><pre>ARG CI_SERVICE<br>ARG COVERALLS_TOKEN</pre><pre>ONBUILD RUN goveralls -coverprofile=./coverage.out -service=$CI_SERVICE -repotoken=$COVERALLS_TOKEN</pre><pre>ONBUILD RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \<br>      -ldflags=&#39;-w -s -extldflags &quot;-static&quot;&#39; -a \<br>      -o /app/app .</pre><p>This Dockerfile is based on the <a href="https://github.com/chemidy/smallest-secured-golang-docker-image">secure Dockerfile example</a> of C Hemidy and his blog post about it is <a href="https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324">here</a>.</p><ul><li>We start with the official Golang 1.14.1 image and use it by sha256 hash for security.</li><li>Always update certificate authority certificates since it is required for TLS enabled calls.</li><li>We used <a href="https://github.com/bgokden/golang_base_builder_image_template/blob/master/tools.go">tools.go</a> file to store common dependencies and install and validate these dependencies.</li><li>Install extra tools you use, I installed <a href="https://github.com/mattn/goveralls">goveralls</a> a tool to update coveralls code coverage results.</li></ul><p>Use <strong>ONBUILD</strong> calls to define commands you want to run when another image is build based on this image. This is important to decide and follow a common build and validation process among the services. Large companies have tooling departments that build these or you can have someone with practical knowledge about these tasks. Unfortunately, it is hard to find these people.</p><p>Here I added test, code coverage check, and standard production build with ONBUILD commands. These will run when the individual developers build their image.</p><p>You can find the source code of this base image here:</p><p><a href="https://github.com/bgokden/golang_base_builder_image_template">bgokden/golang_base_builder_image_template</a></p><p>I have updated one of my weekend projects to use this base image and its Dockerfile turned into this:</p><pre># FROM berkgokden/go_builder_base:v0.0.1 AS builder<br>FROM berkgokden/go_builder_base@sha256:d3098e69bd256a6d93fc9fa81c3256796b3512ae4d724451d3e5d1644f009063 AS builder</pre><pre>FROM gcr.io/distroless/static@sha256:c6d5981545ce1406d33e61434c61e9452dad93ecd8397c41e89036ef977a88f4</pre><pre>COPY --from=builder /app/app /app/app</pre><pre>ENTRYPOINT [&quot;/app/app&quot;]<br>EXPOSE 9090 9091</pre><p>As you can see it is just referencing the layers, copying the application binary, and exposing the ports. If you are going to write many microservices, you need to be able to write short easy to write Dockerfiles. I can even write this by hearth except for the sha256 hashes and it is a secure and tiny image. Only 7.45MB. A practical image for a microservice would be around 10MB.</p><p>Source code and Dockerfile can be found here:</p><p><a href="https://github.com/bgokden/go-http-redirector">bgokden/go-http-redirector</a></p><p>I would like to mention <a href="https://github.com/GoogleContainerTools/distroless">google distroless image</a> here. This image has an image built from scratch that has the bare minimum required to run a binary image without external dependencies. Most of the known vulnerabilities are in these libraries so it is better if we exclude them. Also, it runs the application as a non-root user.</p><p>You can build your own image from scratch but you should definitely check Google Distroless image:</p><p><a href="https://github.com/GoogleContainerTools/distroless">GitHub - GoogleContainerTools/distroless: 🥑 Language focused docker images, minus the operating system.</a></p><p><strong>Sum it up:</strong></p><p>Docker is a great tool to standardize the development, build, and production environment. It can improve and simplify the CI pipeline with some simple steps. Follow these steps and enjoy small and secure docker images.</p><p>Follow me on Linkedin:</p><p><a href="https://www.linkedin.com/in/berkgokden/">Berk Gökden - Senior Software Engineer - Caspar.AI | LinkedIn</a></p><p>Or Github:</p><p><a href="https://github.com/bgokden">bgokden - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3573da77a9d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/continuous-integration-practices-with-docker-part-2-3573da77a9d8">Continuous Integration Practices with  Docker— Part 2</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Practical Rules for Software Development — Part 1]]></title>
            <link>https://medium.com/berk-gokden/practical-rules-for-software-development-part-1-e082378ce332?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e082378ce332</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Thu, 21 May 2020 08:13:38 GMT</pubDate>
            <atom:updated>2020-05-21T08:13:38.210Z</atom:updated>
            <content:encoded><![CDATA[<h3>Practical Rules for Software Development — Part 1</h3><p>I was planning to write a series of blog posts of my experiences in the design principles of software development. I see that even senior developers do not follow these principles. I will avoid design terms and explain how to apply these in practice. <strong>These are not related to my current or previous employer but my general experience over a general period.</strong></p><p><strong>Keep It Simple Stupid. Aka KISS principle.</strong></p><p>Keep your application as simple as possible. If your developers start to complain about “Too many moving parts”, you should stop what you are doing and think about how you can simplify it. <strong>Split your application into simple parts that can be completed by one developer in a maximum of two weeks.</strong> Two weeks is generally accepted as one sprint in Scrum-based development.</p><p>Every service should be simple enough to be re-written in two weeks. You are going to re-write that service multiple times anyway.</p><p>Split your work into <strong>services</strong> and <strong>libraries</strong>.</p><p><strong>Services</strong> should have business logic, one git repo, one deployable Docker image, a README file explaining how to deploy, and use, a CI/CD pipeline connected to it. CD may be excluded if it is a product and deployed externally. Currently, the best practice is to loosely couple CD and CI.</p><p><strong>CI</strong> stands for Continuous Integration, testing, and merging of code.<br><strong>CD</strong> stands for Continuous Deployment, deployment of the service automatically after tests.</p><p><strong>Libraries</strong> should have general logic, helper methods, loggers, any reusable logic. You should split libraries logically into separate repositories, they should have a README explaining how to use them, a CI pipeline, a CD pipeline if the library will be pushed to an artifact repository.</p><p>Libraries are more long term investments. I usually use my free time to write libraries that I may need in the future. It is a good practice to encourage developers to use some of their development time to write libraries and tooling. Usually, Scrum masters and product managers ignore this since they are not directly bringing new features, but it is needed to decrease future work. Having libraries also allows teams to predict future work better.</p><p>Services should be composed of libraries. A service is a glue between libraries. If your service gets too complicated, move complicated parts into separate well tested libraries.</p><p><strong>Use semantic versioning everywhere.</strong></p><p>This is very important, set this up on day one. I usually follow the “v1.2.3” format. I don’t like to use build and pre-release tags because you can not follow iteration. It makes harder to compare the iteration and creates a feeling of stagnation. I also use the “v” prefix since there can be other non-versioned tags like “milestone-1”, “release-1”, “MVP”.</p><p>This version should be your git tag, docker tag, and any tag you use in your artifact repository. Automatically incrementing version tags using special tags in your commit message has become a trend. Many people still do this by hand. Here is the shell script, I wrote in my previous job:</p><p><a href="https://github.com/magneticio/semver-shell">magneticio/semver-shell</a></p><p><strong>Trunk Based Development is your friend.</strong></p><p>Split your work into smaller pieces that can be merged into the master branch without making any compile or build failures. It can be just one method or new constant values. It is hard to review large commits so if you can split your feature into smaller commits it is better. Large commits, usually pass without proper review and testing so bugs go by. It is hard to pinpoint the time which changes caused a bug that you are observing.</p><p>For more explanation:</p><p><a href="https://trunkbaseddevelopment.com/">Trunk Based Development</a></p><p><em>Some product managers do not allow pull-requests/merges that are not directly bringing a feature, which makes trunk-based development impossible. They are simply wrong.</em></p><p>In larger companies, we used the long-running feature branches like“release-24”, “release-for-acme”. Merging them back to master was a big struggle. If you can avoid it, avoid it.</p><p>This post is going too long so I will finish with some flows as a summary:</p><p><strong>Pull-request workflow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*kUWhFdZlO9s2sGpAbbLb3A.png" /></figure><p>Pull-request workflow works only if you have good tests and reviews are in place. Assuming you have 5–9 people teams:</p><p><strong>Reviews:</strong></p><p>There should be one code owner for the part of the code that is being changed. You should have at least 2 reviewers and one of them should be code owner. <a href="https://www.vogella.com/tutorials/Gerrit/article.html#gerrit_voting">Gerrit has a voting based coding review system</a>. Github doesn’t have this but if your team is small enough you can handle this by <strong>common sense</strong>. Github has a setting to define the code owner and there are bots to check the number of reviewers. <strong>Having 2 reviewers means, your developers need to spend 30% of development time on reviewing. </strong>Some of the product managers and the scrum masters plan sprints ignoring code review duration and developers end up overestimating tickets to compensate for this or they settle with not reviewing code at all.</p><p><strong>Code coverage and tests:</strong></p><p>Set up code coverage as a test step, there are so many tools out there eg.: <a href="https://codecov.io/">codecov</a> or <a href="https://coveralls.io/">coveralls</a>. As a good rule, keep your test coverage over 70%. Do not try to achieve 100% code coverage from day one, if you are not a bank or security provider. High test coverage usually decreases flexibility.<em> When developers are forced to write more tests, they settle with writing unnecessary tests or tests which are testing the wrong logic which will hurt you more than having low coverage.</em></p><p>Start with choosing your code repo provider (eg: Github, Bitbucket or Gitlab), then choose a CI provider (eg.: Jenkins, CircleCI, Travis, )</p><p>I have luck with Github + CircleCI + Coveralls for Golang development.</p><p><strong>The most important rule to achieve this is that a developer should be able to develop, test, and build an individual service or library locally without having to set up a complicated build environment.</strong></p><p>Without following this rule, you can not apply any of the principles explained here and you can not have small build iterations.</p><p><strong>CI Pipeline:</strong></p><p>This is a generic CI pipeline, details depend on language and platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*uU38nEU0RlIsa6-WtkAmxA.png" /></figure><p>Golang, Python with Pip and Javascript with NPM can use git as a library repository so for these languages, the library development flow looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*EHyb9Q9L8DgX2wCg4-IElw.png" /></figure><p><strong>CD pipeline:</strong></p><p>I will not explain the CD pipeline here. Previously we were including CD pipeline as a last stage of the CI pipeline but recently <a href="https://fluxcd.io/">FluxCD</a> and <a href="https://argoproj.github.io/argo-cd/">ArgoCD</a> have become CD standards and it is loosely coupled with CI.</p><p><strong>Conclusion:</strong></p><p>To sum up, these are the key concepts of this post:</p><ul><li>Keep it simple stupid.</li><li>Split your work into smaller iterations.</li><li>Do versioning and have stable dependencies.</li><li>These development practices are a commodity, so don’t spend too much time on re-inventing this kind of work.</li></ul><p>Follow me on Github:</p><p><a href="https://github.com/bgokden">bgokden - Overview</a></p><p>Or Linkedin:</p><p><a href="https://www.linkedin.com/in/berkgokden/">Berk Gökden - Senior Software Engineer - Caspar.AI | LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e082378ce332" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/practical-rules-for-software-development-part-1-e082378ce332">Practical Rules for Software Development — Part 1</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is it possible to build a Generic Recommender System With Deep Learning and NLP?]]></title>
            <link>https://medium.com/berk-gokden/is-it-possible-to-build-a-generic-recommender-system-with-deep-learning-and-nlp-ad9b2ed9560c?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad9b2ed9560c</guid>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[lstm]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Sun, 15 Mar 2020 13:01:52 GMT</pubDate>
            <atom:updated>2020-03-15T13:01:52.102Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DlrTD34MWb17KRC9YlhW0Q.jpeg" /></figure><p>This question is on my mind for a couple of years, can we predict the next event in the sequence where the type of events is not known or labeled before.</p><p><strong>Promise:</strong> In this post, I will design a simple recommender system using Keras LSTM model and TensorFlow multi-language universal encoder as embedding to recommend the next two products based on the previous three products based on product transactions.</p><p>First of all, to use deep learning, I needed to find a way to encode events to a vector. I started with Word2Vec and averaging words vectors, then I found out about Doc2Vec from Gensim. The problem with these is the training a model takes time and it required significant cleaning of the input data. Then the transformers arrived. Pretrained transformer models like BERT and GPT-2 revolutionalized the NLP world. But I will use <a href="https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3">Tensorflow Universal Sentence Encoder Multilingual Large model</a> since it is easier to use for my demo case.</p><p><a href="https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3">Tensorflow Universal Sentence Encoder Multilingual Large model</a> creates a 512 float array vector representation of sentences. I won’t get into the detail about this model in this post.</p><p>For reverting back products from vector spaces, I will use a simple nearest neighborhood classifier. Since this is a small dataset, I will use <a href="https://scikit-learn.org/stable/modules/neighbors.html#nearest-centroid-classifier">NearestCentroid Classifier from sklearn library</a>. I will not use a deep learning library for text generation because we have a smaller subset to recommend and text generation is a harder problem. I have built <a href="https://github.com/bgokden/veri">a feature store called Veri to handle larger datasets</a>.</p><p>In the first phase, I will prepare data and convert everything into vector space with <a href="https://tfhub.dev/google/universal-sentence-encoder-multilingual-large/3">Tensorflow Universal Sentence Encoder</a>. I will use <a href="https://www.kaggle.com/carrie1/ecommerce-data/data">an E-commerce Dataset from Kaggle</a>. This dataset includes actual transactions from a UK retailer. But it has two problems where purchases are not actually time-series and descriptions are not sentences, just names of the products. If I can find a better dataset, I will republish new results.</p><p>First, I read the data with pandas and I prepared both data for the nearest neighbor classifier and transaction data. Transaction data should be in the form of 3 inputs and 2 outputs. Each element is a 512 element float array. As a side note, many implementations use embedding as the first layer of their model but I will keep embedding as a separate layer to keep these operations separate. I have grouped transactions into groups of 5, if less than 5, I have padded array with empty strings. Since these transactions are not time-series, I created permutations of arrays and get the subset of 3 elements. I do this if I use LSTMs with unordered data. Using a more general convolution network would be better in this case but I want to develop a generic model that can be used with ordered or unordered data. Although this dataset doesn’t include, website funnel data is usually ordered. I stored prepared data as NumPy arrays to be used for training the model. The code snippet is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44b653c2e23d5fb868a27b324366f189/href">https://medium.com/media/44b653c2e23d5fb868a27b324366f189/href</a></iframe><p>In the second part, I will load the data from the first part then train a multivariate multi-step encoder-decoder LSTM model with Keras where input is 3x512 float and output is 2x512 float. Usually, this model should be optimized by hyperparameter tuning but I will use some logical values that I chose model parameters by hand and my symmetry obsession. I have read the LSTM book of Jason Brownlee and used the example from <a href="https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/">Machine Learning Mastery</a> as a base for this example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba1d320b71c11814bed90380747c0555/href">https://medium.com/media/ba1d320b71c11814bed90380747c0555/href</a></iframe><p>In the third part, I will test the model with some existing data. I will reuse some code from the first part and call the model to make predictions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/789f13939c221a30f57ed101ac3b3f88/href">https://medium.com/media/789f13939c221a30f57ed101ac3b3f88/href</a></iframe><p>Results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d863eec5f771388dc1d6fc54b2542c79/href">https://medium.com/media/d863eec5f771388dc1d6fc54b2542c79/href</a></iframe><p>You can see that mostly the results are logically related to the input. The product named “STORAGE TIN VINTAGE LEAF” is recommended multiple times, I believe this product has its own cluster so anything results in that area end up with this product. The recommender system doesn’t need to be perfect so these results look good enough with little development.</p><p>The advantage of this model is that it can be used for more generic input:</p><pre>Example with existing products:<br>[&#39;BABY BOOM RIBBONS &#39;, &#39;GINGERBREAD MAN COOKIE CUTTER&#39;, &#39;ROSE COTTAGE KEEPSAKE BOX &#39;] =&gt; [&#39;ALARM CLOCK BAKELIKE IVORY&#39;]</pre><pre>Example with non-existing products:<br>[&#39;ribbon&#39;, &#39;cookie cutter&#39;, &#39;rose box&#39;] =&gt; [&#39;DOORKNOB CRACKED GLAZE IVORY&#39;, &#39;ALARM CLOCK BAKELIKE IVORY&#39;]</pre><p>Even when a user didn’t buy any products yet, it is possible to create a recommendation based on the webpage or the information of the user gathered from other sources.</p><p>This kind of model can be saved and used for other e-commerce platforms with little to no training. It has an easy and straightforward development. These examples unfortunately not complete and data is not properly formatted. It would be much better to use it with a time-series funnel dataset.</p><p>Please add your thoughts as a comment.</p><p>Code can be found my GitHub repo:</p><p><a href="https://github.com/bgokden/lstm-recommender-example">bgokden/lstm-recommender-example</a></p><p>I will continue in my next blog post on how to pack and serve this project with a docker image.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad9b2ed9560c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/is-it-possible-to-build-a-generic-recommender-system-with-deep-learning-and-nlp-ad9b2ed9560c">Is it possible to build a Generic Recommender System With Deep Learning and NLP?</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Identity Negotiation]]></title>
            <link>https://medium.com/berk-gokden/secure-identity-negotiation-47db3de684a?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/47db3de684a</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Tue, 12 Nov 2019 01:12:47 GMT</pubDate>
            <atom:updated>2019-11-12T01:18:29.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uMOWFNyEe5VDBAxwKbJsw.jpeg" /></figure><p>I have recently started to work on a<a href="https://github.com/bgokden/gossip-to-gossip/"> secure grpc gossip library</a> with certificate rotation. The main idea was to regularly distribute new certificates over the gossip protocol. I quickly run into the problem that identity negotiation is required. I will explain the problem and my solution.</p><p>The gossip protocol should run on mutual TLS, mutual TLS is very hard without a certificate authority. There should be a way to authenticate a new node to the gossip network. A “registration service” is required where mutual TLS is not needed but regular TLS with a self-signed certificate. So we don’t trust the network there can be man-in-the-middle or replay attacks.</p><p><strong>The problem:</strong></p><p>Node 1 wants to know if node 2 is a friendly node.</p><p>How to achieve this on zero trust network?</p><p><strong>Trial one: passphrase</strong></p><p>I have started with the idea of a pre-shared passphrase but I give up on it quickly because if the network is not secure it is prone to man-in-the-middle attacks and replay attacks. I need something even if somebody able to see the whole communication, it should not be understood.</p><p><strong>Trial two: RSA encrypted passphrase</strong></p><p>I quickly moved to the idea of having asymmetrically encrypting my passphrase. Nodes will share the public key, private key, seed, and a passphrase. Node 1 will encrypt and send the passphrase and node 2 will decrypt and check the passphrase. Sounds good but how the node 2will know the node 1 is actually node 1. Somebody could have captured the message and replaying it.</p><p><strong>Final Trial: RSA encrypted random message with echo</strong></p><p>This time, nodes will share the public key, private key, seed, and a prefix. Node 1 will generate a random message, encrypt and send it to node 2. Node 2 will decrypt it, add pre-defined prefix and encrypt it again and send it back to node 1. Node 1 will decrypt it check it against the prefix and the random message sent. This way node 1 will be sure that it is talking to the right node, then node 1 will decide to send its current certificates.</p><p>This seems to be a good approach security-wise:</p><ul><li>Since the message is generated randomly for each negotiation session, it can not be replayed.</li><li>All messages are random byte arrays so it is not possible to crack it with brute-forcing.</li><li>Prefix makes requests and responses different for negotiation, so both sides are validated.</li><li>Certificates used for encryption is not transferred on the wire.</li></ul><p>You can find the readme and code example on the github:</p><p><a href="https://github.com/bgokden/gossip-to-gossip/tree/master/negotiation">bgokden/gossip-to-gossip</a></p><p>I am not a security researcher so I would like to hear critics if there is a security issue with this approach, so comments are appreciated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47db3de684a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/secure-identity-negotiation-47db3de684a">Secure Identity Negotiation</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Futures in Golang]]></title>
            <link>https://medium.com/berk-gokden/futures-in-golang-aa51af1b81a0?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa51af1b81a0</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 14:11:16 GMT</pubDate>
            <atom:updated>2019-11-10T14:11:16.800Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been programming in Java and Scala for a long time. It is very common to use Futures for concurrency. Some people are obsessed with it.</p><p>This Sunday morning had some time to create a simple library which is somewhat similar to Java Future.</p><p>For starters, here is the link for <a href="https://docs.oracle.com/javase/8/docs/api/index.html?java/util/concurrent/Future.html">Java Future</a> and here is the link for the <a href="https://docs.scala-lang.org/overviews/core/futures.html">Scala Future</a>.</p><p>Go has Goroutine and channels to build basic concurrent programming. So I wanted to build a function that runs the given function inside goroutine and returns the result in a channel.</p><p><em>I feel guilty for creating a channel for only one call but this is more of a utility for beginners, prototyping or low load services. For the advanced use cases, I still recommend creating your channels, goroutines and wait groups.</em></p><p>I wanted to have a wrapper to start a function in a goroutine and get the result from a channel and allow it to set a timeout. I have been doing this in other projects but mostly manually.</p><pre>future := gofuture.FutureFunc(func() int {<br>  return 5<br>})<br>// do something else here<br>// get result when needed<br>result := future.Get()</pre><p>Also set timeout if needed:</p><pre>result := future.GetWithTimeout(3 * time.Second)</pre><p>I run into a problem that golang still doesn’t support generics so Future struct returns an interface and type casting should be handled by the user.</p><p>Future struct:</p><pre>type Future struct {<br> Success          bool<br> Done             bool<br> Result           interface{}<br> InterfaceChannel &lt;-chan interface{}<br>}</pre><p>Future struct currently allows checking if the result is ready and successful.</p><p>Channel kept open after get call, so the user can call GetWithTimeout multiple times. It is ok to leave a channel open, although it is not recommended. To handle this, it is recommended to allow the Future struct to be garbage collected. When all references to a channel are removed channel will be closed and garbage collected. Source: <a href="https://stackoverflow.com/a/36613932/927783">https://stackoverflow.com/a/36613932/927783</a></p><p><strong>Future of Future:</strong></p><p>I would like to use this Future implementation with a Golang Stream library like <a href="https://github.com/vladimirvivien/automi">Automi</a> or a similar library to create easy to write parallel calls.</p><p>Here is the link to the github repo:</p><p><a href="https://github.com/bgokden/gofuture">bgokden/gofuture</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa51af1b81a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berk-gokden/futures-in-golang-aa51af1b81a0">Futures in Golang</a> was originally published in <a href="https://medium.com/berk-gokden">Berk Gökden’s adventures</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing Ingress Services in Istio with Let’s Encrypt on Kubernetes]]></title>
            <link>https://medium.com/vamp-io/securing-ingress-services-in-istio-with-lets-encrypt-on-kubernetes-f6effd93ef06?source=rss-d1ef641932b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6effd93ef06</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Berk Gökden]]></dc:creator>
            <pubDate>Wed, 15 Aug 2018 08:17:56 GMT</pubDate>
            <atom:updated>2018-08-15T08:17:56.845Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rclb9okYbeFN-jJmgbT3bw.jpeg" /></figure><p>This is the third post in our series describing our experiences in adopting Istio for traffic routing on Kubernetes. For more details on what we are trying to achieve with Vamp Lamia and why we choose Istio, please refer to our <a href="https://medium.com/vamp-io/putting-istio-to-work-8513f5218c51">first post</a> and <a href="https://medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2">second post</a>.</p><p>In Vamp.io, we are developing Vamp Lamia to help you connect your services to real world easily and that real world requires ssl/tls connection.</p><p>Recently many browsers and also other technologies started to enforce having an ssl connection.<a href="https://security.googleblog.com/2018/02/a-secure-web-is-here-to-stay.html"> Google Chrome is warning users for http connections.</a> Android is also <a href="https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html">expecting secure connections by defaul</a>t now.</p><p>In the past, it was hard and expensive process to get certificates from an authority. A general solution was needed. Let’s Encrypt offers a practical solution to the problem of getting SSL/TLS certificates when needed. Here is the official mission of Let’s Encrypt</p><blockquote>Let’s Encrypt is a free, automated, and open certificate authority (CA), run for the public’s benefit. It is a service provided by the <a href="https://letsencrypt.org/isrg/">Internet Security Research Group (ISRG)</a>.</blockquote><blockquote>We give people the digital certificates they need in order to enable HTTPS (SSL/TLS) for websites, for free, in the most user-friendly way we can. We do this because we want to create a more secure and privacy-respecting Web.</blockquote><blockquote>source: <a href="https://letsencrypt.org/">https://letsencrypt.org/</a></blockquote><p>In Istio, it is possible to <a href="https://istio.io/docs/tasks/traffic-management/secure-ingress/">secure an ingress service by adding certificates to a gateway </a>. But it is a multistep process and certificate authorisation is not documented. To make this process automated, we have added an integration for Let’s Encrypt to Vamp Lamia.</p><p>There are two approaches accepted by Let’s Encrypt for certificate authorisation; HTTP and DNS. We decided to implement the DNS method first since it can be used with other TCP protocols like gRPC and also allows wildcard domain certificates.</p><p>For DNS authorisation, you still need to have a managed dns service provider. Our development environment is mainly on Google Cloud Platform so we started with integrating Google Cloud DNS, but our system is modularised so it is easy to integrate with other DNS providers such as Amazon Route 53, CloudFlare, etc. As a side note, your DNS provider doesn’t need to be as the same provider as your kubernetes cluster provider. Your cluster can be on AWS and you can still use Google Cloud DNS. Reach out to us if you need some help setting this up.</p><p>We integrated Let’s Encrypt into Gateways creation by exposing a secure hostname parameter. With this hostname, we create both a DNS service entry and a certificate authorisation.</p><p>This is done in multiple steps, so first we will explain the prerequisites.</p><h3><strong>Prerequisites</strong></h3><p>The first step is the Zone domain creation, this is needed for name server redirection. This is the initial step and it may need a manual step so I will try to explain it as much as possible.</p><p>Some name service providers have fixed name servers but Google Cloud DNS creates a set of 4 name servers per zone. You need to set these name servers as your name servers in your domain provider’s settings. This is a one time operation per domain.</p><p>We registered a domain <strong>democluster.net</strong> at <a href="https://www.name.com/">name.com</a> . You can also create a domain at Google Domain but we already had a domain lying around for this blog post. This is an example name server configuration in name.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oc2pbqy5tQel5K8z3oHQ4w.png" /></figure><p>Check if your name server configuration is updated. It is cached over the internet and it may take up to 48 hours to actually update. In our case it took around 2 hours.</p><p>Note that Google DNS has multiple sets of nameservers so when a zone is created you should check the nameservers and update them.<br>You can go to Google DNS page and open your zone, there will be the list of name servers under the type NS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3a4nMn8og60_4v1pxTcupA.png" /><figcaption>Example Zone Record in Google DNS</figcaption></figure><p>When a Gateway is created, Vamp Lamia will set up the zone record for you and subsequently list the name servers in the UI. Let’s Encrypt authentication requires the name servers to be updated.</p><p>Now we can continue with using Vamp Lamia.</p><p><strong>Setting up a gateway and service:</strong></p><p>To install Vamp Lamia, please follow instructions in our <a href="https://github.com/magneticio/vamp2setup">github</a></p><p>For this post, we will use vamp-shop as a deployment, it is included in our package under samples. Vamp Shop is an imaginary e-commerce website, where we test our canary releasing features. We have mentioned it in <a href="https://medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2">our A/B testing blog post</a>, we are using nearly the same architecture in this post.<br>Please run <a href="https://github.com/magneticio/vamp2setup/blob/master/samples/experiment-demo/demo-setup.sh">demo-setup.sh</a> to deploy Vamp Shop to your kubernetes cluster.</p><p>Vamp Lamia regularly checks the cluster and installs missing components of Istio and detects new deployments, it is recommended to wait on the “List Virtual Cluster” page until you see the “vamp-demo” namespace appear, when it is available you can edit it.</p><p>For this demo you need to add google_project_id and google_service_account as metadata. In order to do that you have to create service account and copy the contents of the json file to value area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ct237GU3VhYDNW4gaxaqXQ.png" /></figure><p>We are going to create:</p><ul><li>a service</li><li>a destination rule</li><li>a gateway</li><li>a virtual service</li></ul><p>Create a service as given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C56YXx3aVshqZE-7dLV8gg.png" /></figure><p>Create a destination rule as given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fkLMgugQdaFL3D-Z2Otw-A.png" /></figure><p>Create a gateway as seen below. Please note that you need to use another hostname from a domain that you own. The “Secured Host” will be used for registering to DNS and to Let’s Encrypt. There can be only one Secured Host per port due to TCP protocol limitations. The default port for HTTPS is 443.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uEvOJ5PgWtiP_vzp62u3w.png" /></figure><p>Create a virtual service as given below, here the protocol is http, the SSL/TLS termination is happening at the edge of the cluster and internal services can continue using http.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uEcLnNlfbiu-2zcv7-qtgA.png" /></figure><p>You may need to wait to get a notification that the gateway has been updated in the UI. You can view the “Gateway Details” page to see the list of current name servers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j6C-hKQrkkPi6ZL6Eh9Gwg.png" /></figure><p>if everything went well, you can check the website on your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bvRbHrMS1F0LUdJ40XRD-Q.png" /><figcaption>Certificate is visible on a browser</figcaption></figure><p><strong>What happened?</strong></p><p>When a secure host is defined, Vamp Lamia first sets up a gateway and gets a public ip and then tries to communicate with your dns provider and sets up an A Record, so that your service is reachable by the ip address. Finally, Vamp Lamia is ready to set up certificates.</p><p>Vamp Lamia will generate certificates, authenticate with Let’s Encrypt using DNS Challenge and set it up using your DNS provider. The result of this process is also visible on Google DNS page as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EgV3LkBL14OzSi-86Q0lfQ.png" /><figcaption>DNS Records after the Let’s Encrypt authorisation</figcaption></figure><p>When a client asks certificate registration, Let’s Encrypt asks to authorise for that domain. There are two possible ways, an HTTP challenge and a DNS Challenge. We are using DNS challenge since it is more flexible. Let’s Encrypt gave a digest hash and we inserted a TXT record under <em>_acme-challenge.shop.democluster.net.</em></p><p>Finally, Vamp Lamia inserts the certificates into the Istio Gateway.</p><p>Please note that, Vamp Lamia makes some assumptions regarding hostnames, When you have a service hostname like service-name.domain-name.com. We assume that domain-name.com will be used as your zone name. We currently create a certificate per hostname, but we are planning to add domain-wise certificates in a later release.</p><p>With the current state of internet, it is crucial to have SSL/TLS certificates. As we mentioned, since Google and many other software providers are pushing for HTTPS as default in browsers, it is vital to have secure services. With this feature, in a Vamp Lamia managed cluster, it is very easy to set up a secure service and expose it to the real world.</p><p>See you in the next post and check our <a href="https://github.com/magneticio/vamp2setup">github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6effd93ef06" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vamp-io/securing-ingress-services-in-istio-with-lets-encrypt-on-kubernetes-f6effd93ef06">Securing Ingress Services in Istio with Let’s Encrypt on Kubernetes</a> was originally published in <a href="https://medium.com/vamp-io">vamp.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>