# betclic-tech - Medium

Technical publication from our Betclic teams - Medium

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Sealed classes in Kotlin

DevFeed: [Sealed classes in Kotlin](<https://devfeed.tech/articles/sealed-classes-in-kotlin-23690.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/sealed-classes-in-kotlin-74b1d28aaef2?source=rss----7e406d68d94b---4>)

Author: Florian Garcia

Published: 2022-09-26T13:51:32Z

Content type: tutorial

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [Code](<https://devfeed.tech/topics/code.md>), [Exception](<https://devfeed.tech/topics/exception.md>)

Tags: [classes](<https://devfeed.tech/tags/classes.md>), [code](<https://devfeed.tech/tags/code.md>), [exception](<https://devfeed.tech/tags/exception.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [sealed](<https://devfeed.tech/tags/sealed.md>), [sealed-classes](<https://devfeed.tech/tags/sealed-classes.md>)

### AI overview

A tutorial explaining how Kotlin sealed classes and interfaces represent restricted class hierarchies. It shows how they help the compiler identify all supported cases and avoid missing-case handling when the hierarchy changes.

### Source excerpt

In this article, we will talk about sealed classes and interfaces. What they are, what problem they solve and how we can leverage this in real life. The problem Let's take the following code: https://medium.com/media/f1f04b5ee8f0bfc98d41cad1fbd803a2/href Our code only handles two types of animals (cats and dogs). But the compiled code does not know that only those two types exist. This means we have to add this ugly else block in our when. This can be a real issue because you start to think about what to do in a situation that shouldn't exist but that will potentially exist in the future. For instance, say that tomorrow we add cows to the list of supported animals, the code will compile just fine because we have put the else block. We could change the else part to throw an exception but Kotlin does not have checked exceptions (so it's easy to forget to catch one), and thus we end up with runtime exceptions. That's a bit sad because we probably want to know at compile time that we need to handle this new case. Solution As you probably have guessed, the solution is sealed classes or interfaces. But what are they? From the Kotlin documentation: Sealed classes and interfaces represent restricted class hierarchies that provide more control over inheritance. All direct subclasses of a sealed class are known at compile time. No other subclasses may appear after a module with the sealed class is compiled. For example, third-party clients can't extend your sealed class in their code. Thus, each instance of a sealed class has a type from a limited set that is known when this class is compiled. If rephrased, this means that we can define a bounded hierarchy. One of the important things to know when working with sealed classes is that you cannot instantiate the sealed class; thus only the leaves of the structure exist at runtime (but you can use the interface as a type). When we develop applications that are not libraries, it is pretty rare to allow an abstract class / interfac

## Automate AWS Athena Partitions for Organization CloudTrail Logs and VPC Flow Logs

DevFeed: [Automate AWS Athena Partitions for Organization CloudTrail Logs and VPC Flow Logs](<https://devfeed.tech/articles/automate-aws-athena-partitions-for-organization-cloudtrail-logs-and-vpc-flow-logs-23687.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/automate-aws-athena-partitions-for-organization-cloudtrail-logs-and-vpc-flow-logs-2f322291c897?source=rss----7e406d68d94b---4>)

Author: Aurelien Cerveaux

Published: 2022-09-15T06:39:58Z

Content type: tutorial

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [AWS CloudTrail](<https://devfeed.tech/topics/aws-cloudtrail.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [VPC Flow Logs](<https://devfeed.tech/topics/vpc-flow-logs.md>), [Amazon S3](<https://devfeed.tech/topics/amazon-s3.md>), [AWS CloudFormation](<https://devfeed.tech/topics/aws-cloudformation.md>), [DynamoDB](<https://devfeed.tech/topics/dynamodb.md>), [JSON](<https://devfeed.tech/topics/json.md>)

Tags: [amazon-s3](<https://devfeed.tech/tags/amazon-s3.md>), [athena](<https://devfeed.tech/tags/athena.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-cloudtrail](<https://devfeed.tech/tags/aws-cloudtrail.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [cloudformation](<https://devfeed.tech/tags/cloudformation.md>), [cloudtrail](<https://devfeed.tech/tags/cloudtrail.md>), [dynamodb](<https://devfeed.tech/tags/dynamodb.md>), [events](<https://devfeed.tech/tags/events.md>), [json](<https://devfeed.tech/tags/json.md>), [vpc-flow-logs](<https://devfeed.tech/tags/vpc-flow-logs.md>)

### AI overview

A tutorial explains how to automate daily AWS Athena partition creation for organization-level CloudTrail and VPC Flow Logs. It describes using Amazon S3, AWS Glue Data Catalog, CloudFormation, SAM, Lambda, DynamoDB, and EventBridge to improve query efficiency and reduce scanned data and cost.

### Source excerpt

This article's goal is to explain how to query efficiently, and at low cost with AWS Athena, AWS CloudTrail logs, or VPC Flow logs by automating the creation of Athena partitions daily. AWS CloudTrail AWS CloudTrail is a service that records all API Calls and Events for AWS Accounts, including details on calls made to your AWS Services and the Console as well. Activated at the Organization level, CloudTrail logs help you in several cases: Simplified Compliance Summarizing Accesses Security Analysis and Troubleshooting Monitoring Users and Resources Activities Governance and Investigation CloudTrail Logs are delivered in an S3 Bucket in JSON format through many small files that make these difficult to operate and request. VPC Flow Logs VPC Flow Logs is a feature that allows you to capture traffic information going to and from your network interfaces in your VPC. It helps you to: Analyze and troubleshoot network issues Determine the direction of your traffic Monitor the traffic Like CloudTrail Logs, Flow Logs are published in an S3 Bucket for all accounts in the Organization. AWS Athena AWS Athena is a query service that permits you to analyze data directly in an Amazon S3. You can create tables in Athena which use AWS Glue Data Catalog and are based on an S3 location. To query efficiently and with less scanned data and optimize the cost, we need to create some partitions. To know more about Tables, Databases, and Catalog in Athena. Automate Partitions Creation In our case, we are using CloudTrail Logs and VPC Flow Logs to detail the solution and the source code. All is done in CloudFormation and using SAM to deploy the Lambda. Global Overview We have several parts to automate the creation of our partitions. A common part containing: The Lambda is used to create partitions concerning different log types A DynamoDB table used to store partition names A specific part for each log type contains: The Glue Table with the proper structure An EventBridge Rule to trigger the

## AWS SDK for Kotlin

DevFeed: [AWS SDK for Kotlin](<https://devfeed.tech/articles/aws-sdk-for-kotlin-23688.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/aws-sdk-for-kotlin-222e7e7f0ac0?source=rss----7e406d68d94b---4>)

Author: thiiozz

Published: 2022-08-23T07:05:18Z

Content type: tutorial

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [SDKs](<https://devfeed.tech/topics/sdks.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [DynamoDB](<https://devfeed.tech/topics/dynamodb.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>), [Amazon S3](<https://devfeed.tech/topics/amazon-s3.md>), [Amazon Simple Queue Service (SQS)](<https://devfeed.tech/topics/amazon-simple-queue-service-sqs.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [amazon](<https://devfeed.tech/tags/amazon.md>), [api](<https://devfeed.tech/tags/api.md>), [async](<https://devfeed.tech/tags/async.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [aws](<https://devfeed.tech/tags/aws.md>), [backend](<https://devfeed.tech/tags/backend.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [dynamodb](<https://devfeed.tech/tags/dynamodb.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [sdk](<https://devfeed.tech/tags/sdk.md>)

### AI overview

This tutorial introduces the beta AWS SDK for Kotlin, an open-source Apache 2.0 project built from scratch in Kotlin. It demonstrates configuring the SDK with Gradle, creating a DynamoDB client, performing table operations, and using fluent syntax and asynchronous calls compared with the Java SDK.

### Source excerpt

During AWS re:Invent 2021, Amazon announced an AWS SDK for Kotlin. At Betclic, we were very enthusiastic about this news as we use the Kotlin language for both Frontend and Backend apps, and we love it. One year later, the first beta releases are available for developers to preview. Let's discover them! Forewords This SDK can be used to develop applications that interact with services such as DynamoDB, S3, SQS, and many more (API reference). Like other SDKs, this new one is an AWS open-source project available under the Apache 2.0 licence. The project is still in beta "developer preview" phase, and it should not be used in production yet. You can follow developments on the public road map. After the first official release, daily releases are planned to make services updates available within the SDK under 24 hours. Interesting point, this new SDK has been re-built from scratch using Kotlin rather than re-using the existing Java SDK. Let's dig into concrete examples around DynamoDB. Hello SDK ! First, you need to add the SDK dependency in your project, for example, with Gradle. https://medium.com/media/9045f8ec2d12ecbc65bba8edb7d8e611/href Each AWS services have its own standalone, independent and light dependency. Then we can initiate our DynamoDB client with https://medium.com/media/e48bff2f4b6a43e17060d0ca67f5d82f/href The default behaviour of the client can be configured in many ways: Credentials provider (Profile, environment, sts, SSO (soon) ...) Logging backed by Slf4j Http engine fully overridable Retry strategy, AWS region, services endpoints and so on With our project and client correctly setup, we can make our first call https://medium.com/media/7c35f36e7c35b52988464e9a59c1d11a/hrefFluent Kotlin Syntax Moving forward, let's assume we have an existing DynamoDB table "sports" with a single attribute "name" We can put a new item with https://medium.com/media/2df0a1bd5cf14c6ad8586bae1afc85d7/href And get it back with https://medium.com/media/8be66a2add009fd6021c8

## Should we consider migrate to Amazon EventBridge from Amazon SNS + SQS ?

DevFeed: [Should we consider migrate to Amazon EventBridge from Amazon SNS + SQS ?](<https://devfeed.tech/articles/should-we-consider-migrate-to-amazon-eventbridge-from-amazon-sns-sqs-23692.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/should-we-consider-migrate-to-amazon-eventbridge-from-amazon-sns-sqs-4adc8950eca?source=rss----7e406d68d94b---4>)

Author: Guillaume Lannebere

Published: 2022-02-01T14:45:47Z

Content type: article

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Amazon EventBridge](<https://devfeed.tech/topics/amazon-eventbridge.md>), [Amazon Simple Queue Service (SQS)](<https://devfeed.tech/topics/amazon-simple-queue-service-sqs.md>), [event driven](<https://devfeed.tech/topics/event-driven.md>), [Architecture & Design](<https://devfeed.tech/topics/architecture-design.md>), [Microservice](<https://devfeed.tech/topics/microservice.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [Monitoring](<https://devfeed.tech/topics/monitoring.md>), [Latency](<https://devfeed.tech/topics/latency.md>)

Tags: [amazon-eventbridge](<https://devfeed.tech/tags/amazon-eventbridge.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [aws](<https://devfeed.tech/tags/aws.md>), [event-driven](<https://devfeed.tech/tags/event-driven.md>), [eventbridge](<https://devfeed.tech/tags/eventbridge.md>), [latency](<https://devfeed.tech/tags/latency.md>), [microservices](<https://devfeed.tech/tags/microservices.md>), [monitoring](<https://devfeed.tech/tags/monitoring.md>), [net](<https://devfeed.tech/tags/net.md>), [sns](<https://devfeed.tech/tags/sns.md>), [sqs](<https://devfeed.tech/tags/sqs.md>)

### AI overview

The article examines Betclic's event-driven architecture requirements and its early-2019 decision to combine Amazon SNS with Amazon SQS. It presents the decision in the context of unpredictable traffic, multiple consumers, event replay, monitoring, schema management, language interoperability, analytics, autoscaling, low latency, high availability, AWS integration, and cost.

### Source excerpt

Should we consider migrating to Amazon EventBridge from Amazon SNS + SQS? In early 2019, Betclic was in a corner, and we decided to migrate to microservices approach and migrate to the cloud. The first step of this change was the implementation of an Event Driven Architecture (EDA). Betclic presentation Before speaking of architecture and EDA, it's essential to know what Betclic is doing to understand our choice quickly. Betclic is a French online gambling company. Betclic operates in Sports betting, horse race betting, and online poker. The specificity of gambling is that we don't have predictive traffic. We have high traffic peaks during significant events and weekends. We can see an example of traffic on a soccer event: Example of trafficEDA wishlist When beginning 2019, we did a workshop to identify the key features of our ideal EDA; we would like something: allowing multiple reads: the same message can be read by various services with error recovery: in case of error, we would like to replay events easy to monitor: particularly with Datadog, our centralized monitoring solution with schema registry language-agnostic: we use 3 main languages .net, Kotlin, and Typescript (for Lambda), and the chosen solution must work with all languages with analytics capabilities: we would like to integrate all our events of EDA in our data lake fully managed with auto scaling: essential feature for us; we have unpredictable traffic with big spikes at the end of matches, so we need to have an EDA to be able to absorb our spikes with low latency and high availability: also an essential feature, we would like our EDA to serve critical use cases for our final users, so we want something the most real-time and the most available possible well-integrated with AWS services: EDA is one of our first bricks in the cloud, but we want something to help us to migrate to AWS easy to use: we want all the time something easy to use :) but here it's particularly true because EDA is a centralized

## Building a Segmented Progress Bar in Android

DevFeed: [Building a Segmented Progress Bar in Android](<https://devfeed.tech/articles/building-a-segmented-progress-bar-in-android-23689.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/building-a-segmented-progress-bar-in-android-e3f198db393d?source=rss----7e406d68d94b---4>)

Author: Stephen Vinouze

Published: 2021-11-30T15:24:34Z

Content type: tutorial

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Canvas](<https://devfeed.tech/topics/canvas.md>), [User Interfaces](<https://devfeed.tech/topics/user-interfaces.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [building](<https://devfeed.tech/tags/building.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [mobile-app-development](<https://devfeed.tech/tags/mobile-app-development.md>), [programming](<https://devfeed.tech/tags/programming.md>), [ui](<https://devfeed.tech/tags/ui.md>), [user-experience](<https://devfeed.tech/tags/user-experience.md>), [user-interfaces](<https://devfeed.tech/tags/user-interfaces.md>)

### AI overview

A tutorial on building a segmented progress bar in Android by creating a custom View and drawing the interface with Canvas, Paint, and Path objects. It introduces the progress bar's segmented shapes and animation, then begins with a simpler one-segment implementation and discusses avoiding object allocation inside onDraw().

### Source excerpt

Leverage the power of custom drawing.Photo by Daniel Cheung on Unsplash At Betclic, we've proudly released our first in-app metagaming experience. And believe me, it's a huge step forward in the sportsbook industry. Challenging our users on different betting situations and rewarding them instantly was unheard of amongst our competitors. To achieve this, we wanted to bring the best user experience possible to engage our users. Amongst many topics, we've worked on the progression experience. We decided to build an exciting progress bar to reward our users for their progression. When it comes to building user interfaces (UI), you'll often rely on available tools provided by the SDK. However, there are times when your UI requirements prevent you from using them. You may try to tweak your tools, but it just won't fit the bill. To give the wanted look and feel of this progress bar, we decided to draw it ourselves. It turns out it's not as complicated as one may think. Creating Your Custom View Imagine a painter in front of a whiteboard. He'll need a set of brushes along with paint buckets. In Android, the whiteboard would be the Canvas. To draw on it, you'll need Paint objects instead of brushes and paint buckets. Finally, you'll use Path objects to direct the painter's arm onto the Canvas. We can manipulate all of the objects above directly inside a View. More specifically, all the magic happens in the onDraw() callback. https://medium.com/media/edb134052a28bb1bdf476877ee1cd965/href Coming back to the progress bar, let's start by breaking it down. We have a set of quadrilaterals displaying different angles. They're spaced from each other and have a filled state without space. Finally, we have a wavy animation synchronized with its filling progress. Before trying to match all these requirements, we can start with a simpler version. Don't worry, though. We'll get to the bottom of it! Drawing a One-Segment Progress Bar The first step would be to draw its most basic version:

## Serverless Proxy with AWS API Gateway and AWS Lambda

DevFeed: [Serverless Proxy with AWS API Gateway and AWS Lambda](<https://devfeed.tech/articles/serverless-proxy-with-aws-api-gateway-and-aws-lambda-23691.md>)

Original publisher: [Read original article](<https://medium.com/betclic-tech/serverless-proxy-with-aws-api-gateway-and-aws-lambda-c09bd1c20c84?source=rss----7e406d68d94b---4>)

Author: Guillaume Lannebere

Published: 2021-11-10T08:23:55Z

Content type: tutorial

Language: en

Sources: [betclic-tech - Medium](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Amazon API Gateway](<https://devfeed.tech/topics/amazon-api-gateway.md>), [AWS Lambda](<https://devfeed.tech/topics/aws-lambda.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [VPC](<https://devfeed.tech/topics/vpc.md>), [Serverless](<https://devfeed.tech/topics/serverless.md>), [Amazon EC2](<https://devfeed.tech/topics/amazon-ec2.md>), [Python](<https://devfeed.tech/topics/python.md>), [GitHub](<https://devfeed.tech/topics/github.md>)

Tags: [api-gateway](<https://devfeed.tech/tags/api-gateway.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-lambda](<https://devfeed.tech/tags/aws-lambda.md>), [ec2](<https://devfeed.tech/tags/ec2.md>), [github](<https://devfeed.tech/tags/github.md>), [python](<https://devfeed.tech/tags/python.md>), [rest](<https://devfeed.tech/tags/rest.md>), [serverless](<https://devfeed.tech/tags/serverless.md>), [vpc](<https://devfeed.tech/tags/vpc.md>)

### AI overview

This tutorial explains how to use a public AWS API Gateway and a Lambda function attached to a VPC as a serverless proxy between public and private subnets or instances. It covers forwarding GitHub webhook requests to a private EC2 instance, Lambda configuration with Python and an environment variable, and the distinction between REST and HTTP APIs.

### Source excerpt

It's sometimes difficult to communicate between public and private subnet in AWS. We will see how we can easily do that with the help of API Gateway and AWS Lambda. Use case exampleExample 1 It's sometimes necessary to have a Github repository communicating with a private EC2 instance. But when an instance is private, it can be really complicated without impacting the security of the instance. Solution Github Webhook calls a Public API Gateway, API Gateway triggers a Lambda attached to VPC. The role of this Lambda is to forward the content of the Github Webhook to the EC2 instance. Remark: An AWS Lambda attached to a VPC isn't deployed inside the VPC, an Elastic Network Interface (ENI) is created to link the Lambda function and the different subnets inside the VPC. Example 2 Other example, we may need to communicate between a public instance inside a public subnet and a private instance inside a private subnet inside a VPC. For security reason, direct routing between Public subnet and private Subnet is not possible. So, to facilitate this, it's possible to use this solution of Serverless Proxy. Solution On the same way as Solution 1, we can communicate between Public and Private instance via a Serverless Proxy thanks to AWS Api Gateway and AWS Lambda. This solution is easy to implement, highly scalable, secure and not expensive. ImplementationAWS Lambda Lambda function is quite simple. The goal of this lambda is just to forward the information received from API Gateway to the destination inside VPC. Here we use python and Lambda function is as simple as that: https://medium.com/media/f5360ab428b2536b8f1d4aa84cb140fc/href To redirect requests I use the python lib urllib3, for more information or if you want to update the code check the official documentation. To facilitate the deployment, backend url is passed in environment variable. This lambda need to be attached to a VPC. To know how to optimize Lambda for cost and/or performance, 2 tools exists: the well know AW