# Betclic Tech

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: article

Language: en

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

Topics: [sealed class](<https://devfeed.tech/topics/sealed-class.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [sealed interface](<https://devfeed.tech/topics/sealed-interface.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>), [interface](<https://devfeed.tech/topics/interface.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Custom exceptions](<https://devfeed.tech/topics/custom-exceptions.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [exception](<https://devfeed.tech/tags/exception.md>), [exceptions](<https://devfeed.tech/tags/exceptions.md>), [hierarchy](<https://devfeed.tech/tags/hierarchy.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.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

Kotlin sealed classes and interfaces define a bounded hierarchy whose direct subclasses are known at compile time, enabling exhaustive `when` handling without a fallback branch. The article illustrates using this for animal types and for service error results: wrapping known failures in a sealed hierarchy can make newly added cases visible to the compiler and give errors clearer domain meaning. Sealed hierarchies can include intermediate levels while retaining exhaustive handling. The author cautions that openness may be preferable in libraries when users need to add implementations, and notes that the exception-wrapping discussion is brief.

### 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: article

Language: en

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

Topics: [VPC Flow Logs](<https://devfeed.tech/topics/vpc-flow-logs.md>), [AWS CloudTrail](<https://devfeed.tech/topics/aws-cloudtrail.md>), [table-partitioning](<https://devfeed.tech/topics/table-partitioning.md>), [Amazon DynamoDB](<https://devfeed.tech/topics/amazon-dynamodb.md>), [AWS CloudFormation](<https://devfeed.tech/topics/aws-cloudformation.md>), [AWS Glue](<https://devfeed.tech/topics/aws-glue.md>), [Amazon EventBridge](<https://devfeed.tech/topics/amazon-eventbridge.md>)

Tags: [amazon-s3](<https://devfeed.tech/tags/amazon-s3.md>), [athena](<https://devfeed.tech/tags/athena.md>), [automate](<https://devfeed.tech/tags/automate.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-athena](<https://devfeed.tech/tags/aws-athena.md>), [aws-glue](<https://devfeed.tech/tags/aws-glue.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [cloudformation](<https://devfeed.tech/tags/cloudformation.md>), [cloudtrail](<https://devfeed.tech/tags/cloudtrail.md>), [code](<https://devfeed.tech/tags/code.md>), [cost](<https://devfeed.tech/tags/cost.md>), [daily](<https://devfeed.tech/tags/daily.md>), [dynamodb](<https://devfeed.tech/tags/dynamodb.md>), [eventbridge](<https://devfeed.tech/tags/eventbridge.md>), [lambda](<https://devfeed.tech/tags/lambda.md>), [organization](<https://devfeed.tech/tags/organization.md>), [partitions](<https://devfeed.tech/tags/partitions.md>), [query](<https://devfeed.tech/tags/query.md>), [s3](<https://devfeed.tech/tags/s3.md>), [sam](<https://devfeed.tech/tags/sam.md>), [vpc-flow-logs](<https://devfeed.tech/tags/vpc-flow-logs.md>)

### AI overview

The excerpt describes a daily process for creating Athena partitions to reduce scanned data and query costs for organization-wide CloudTrail and VPC Flow Logs stored in S3. The proposed deployment uses CloudFormation and SAM: a shared Lambda creates partitions for different log types, while DynamoDB stores partition names so the system can check whether a partition already exists without querying Athena. Each log type has its own Glue table with an appropriate structure and an EventBridge rule that triggers the Lambda daily with specific input. The excerpt ends while introducing the DynamoDB partition structure, so it does not show the implementation details or the rest of the workflow.

### 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

## 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](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [User Experience](<https://devfeed.tech/topics/user-experience.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [drawing](<https://devfeed.tech/tags/drawing.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>), [progress](<https://devfeed.tech/tags/progress.md>), [ui](<https://devfeed.tech/tags/ui.md>), [user-experience](<https://devfeed.tech/tags/user-experience.md>), [view](<https://devfeed.tech/tags/view.md>)

### AI overview

Betclic's custom Android progress bar uses drawing in a custom View's onDraw() callback because the SDK's standard UI tools did not fit the desired design. The bar is composed of angled quadrilaterals with gaps, a filled state that bridges those gaps, and a wave animation synchronized with progress. The excerpt begins with a simpler one-segment rectangle before tackling those requirements. It advises creating Paint and Path objects outside onDraw(), since the callback runs frequently and repeated allocations can exhaust memory; it then favors drawing point by point to support more complex shapes.

### 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](<https://devfeed.tech/sources/betclic-tech-medium.md>)

Topics: [Serverless](<https://devfeed.tech/topics/serverless.md>), [AWS Lambda](<https://devfeed.tech/topics/aws-lambda.md>), [proxy](<https://devfeed.tech/topics/proxy.md>), [Amazon VPC](<https://devfeed.tech/topics/amazon-vpc.md>), [gateway](<https://devfeed.tech/topics/gateway.md>), [REST API](<https://devfeed.tech/topics/rest-api.md>), [API](<https://devfeed.tech/topics/api.md>), [serverless framework](<https://devfeed.tech/topics/serverless-framework.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>), [network-interface](<https://devfeed.tech/tags/network-interface.md>), [proxy](<https://devfeed.tech/tags/proxy.md>), [python](<https://devfeed.tech/tags/python.md>), [security](<https://devfeed.tech/tags/security.md>), [serverless](<https://devfeed.tech/tags/serverless.md>), [urllib3](<https://devfeed.tech/tags/urllib3.md>), [use-case](<https://devfeed.tech/tags/use-case.md>), [vpc](<https://devfeed.tech/tags/vpc.md>)

### AI overview

A public API Gateway can relay requests to a private VPC backend through a VPC-attached Lambda, which forwards the request using Python and urllib3. The article gives a GitHub webhook-to-private-EC2 example and a public-subnet-to-private-subnet example, noting that the Lambda connects through an ENI. It recommends REST API when calls cannot be authenticated, such as GitHub webhooks; HTTP API may suit authenticated calls when price matters. REST API supports features unavailable or harder to configure for HTTP API in the described Serverless Framework setup, including API keys, resource policies, and throttling configuration. The article also recommends restricting Lambda egress to the backend, setting a short timeout, and protecting the public gateway with suitable throttling and authentication or other controls. A private ALB/NLB integration via VPC Link is presented as a simpler, less customizable alternative where supported.

### 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