Posts

Showing posts with the label Scala

Scala TestContainers

Image
TestContainers is a great project for integration tests, mocking, and even for Chaos Engineering. Scala TestContainers is the library in the form of idiomatic-scala with some sugar to make it even easier to use it. I want to show you guys how we can use Scala Test Containers in an SBT 1.5.0 Project using Scala Spec in order to test as MySQL docker container. So let's get started!

Fat Jar with Scala 2.13 and Sbt 1.5

Image
Fat Jar is a very useful technique. Having one jar and one jar only makes the distribution of software much easier and also mantaince much more sense as you need to roll out bug fixes and changes. Scala allows us to create self-package, self-executing one single fat jat by using the Assembly plugin. Today I want to share a simple POC and video I made showing how we can create a Fat Jar using Scala, Assembly, and Sbt. The code will be using a java dependency, a project called Apache Commons Lang .  So let's get started! The Video The Code https://github.com/diegopacheco/scala-playground/tree/master/fatjar-assembly-sbt-1.5.0 Cheers, Diego Pacheco

Scala 3.0

Image
Scala 3.0 is not out yet but has some interesting new features. I'm still digesting some features some I have some mixed feelings about it. One of the main big changes is the support for Python-like syntax. Scala 3.0 has lots of shortcuts, types of convenience, and different ways to do generics. Scala always had the philosophy to be flexible on the language level and let the tools and companies restrict functionality, so this still pretty much very true. I made a series of 3 videos going over some of the changes in Scala 3. This material is highly inspired by the scala 3 boo/docs. Some code and features on the videos will not be limited by scala 3 but also cool things about scala 2 or even scala in general but mostly I will be talking about scala 3.0. Keep in mind scala 3 is not final so things could change but I believe you gonna be able to have a good sense of what to expect and what's going on. So Let's get started. 

Scala Accord

Image
Accord is an interesting lib for validations. Accord is composable, simple, self-contained, and integrated with ScalaSpecs for instance. In Java, validations are often done via annotations. In general, there is an abuse of annotations in Java mostly because there is a lack of Macros which we have in Scala and Rust for instance. I really like the Accord approach to validations where we dont throw Exceptions and we can extend and re-use validations across the type system. So today I made a simple code with Scala and Accord using SBT as-built system and a video to explain in more detail. So let's get started. 

Scala Tinylog

Image
I personally have a deep passion for lean libraries. Binary Coupling and distributed monolith kill all services initiatives. Shared libraries are often controlled or done with attention and care. The result is catastrophic, developer experience goes down, the ability to the chance version in isolation goes to space and complexity grows as productivity and migrations become more and more consuming. Tinylog has my respect. I love simple, no 3rd party dependencies libraries. So today I want to show how tinylog is cool and yet powerful. I made a video and a simple Scala project using SBT. So Let's get started, 

Memcached with Scala Shade

Image
Memcached is a powerful and battle-tested key-value store. Netflix is one of the many companies that use Memcached at scale. Memcached has a simple design and yet powerful. Redis is great because of the commands and data structure diversity however Redis is not multi-thread and Memcached is. Thats the biggest advantage of Memcached. Scala, it's a powerful and complete modern post-functional language for the JVM. Today I want to show how we can use MemcacheD and Scala together using the Shade library. Shade is part of monix which is a functional multi-thread solution. Today I made a video showing how we can use Memcached and shade in Scala using SBT as a build system. So without further due, let's get started. 

Fun with Akka Actor System

Image
Akka is a kick as technology. Today I want to share a video I made about how we can model an actor system using Akka, Scala, SBT, and IntelliJ Idea. We will model a vending machine using Akka and Scala. We will take advantage of the Scala Type system and Akka typed actors. Type Systems are great because they make programming more secure and prevent bugs and require less testing since the compiler does more for you. For this video, we also will be using SBT 1.4.0, Scala 2.13, and Akka 2.6. So I hope you guys like it. So let's get started!

Running a rich Microservice constellation in Kubernetes

Image
Languages have trade-offs like any solution in tech. Microservices are great for many reasons, one of them allows the best tool for the job. Kubernetes allows us to have the same operational standards and procedures even using different languages and solutions. For this blog post, I want to show a simple project I build which is a constellation of services. There are 5 microservices, written in several languages like Scala, Java, Go, Python and Rust. The services do a pretty basic math operation like (+, - , / , *) and the Scala one does the aggregation and orchestrate the other services using a polish notation algorithm and REST calls.

Having fun with Cats

Image
Cats is a library for Functional Programming in Scala. The name come from the Inspiration by the Category Theory  so Cats is short for Category Theory. Cats are about types, Type System and having abstractions to make it easy to work with them. If you want to go to the next level of function programming Cats is the way to go, however, I need to say that it's hard, get the ideas to take time, understand the terms, principles, and applications takes times as well. At the end of the day, this is about style so there is no right or wrong. Recently I made a post about Monads so it might be useful for you to read it if you did not read it yet. This post won't be monad heavy but reading about monads will make it easy to understand some things here. It's fine if you don't understand everything, I'm 100% sure I don't understand everything and there are lots of ideas and concepts that I still learning. So this takes time. I don't think this is something...

Scala Monads 101

Image
What is a monad ? It's easy to read lots of sites and still don't get the idea. Many people already used monads but few really understand them truly. Monads are a kind of a Myth in Scala for lots of developers. ItÅ› possible to code without creating your own monads? Yes for sure it is. It's very likely you already create abstractions which were similar to monads but with different names. Here are some samples of Monads in Scala: Try , Either and Option . We have some of this monads in Java 8 as well like Optional . Monads come from the Category Theory which is a branch from Math. Monads are very strong concepts in Haskell Language for instance. IMHO one of the reasons why use Monads rather than your uncle abstraction is that they are universal and in theory, they are easier to understand, in practice if you don't study math, Category Theory and Functional Programming principles actually monads will sound much harder than you user uncle abstractions. So, in other word...

Experiences Building & Running a Stress Test / Chaos Platform

Image
Stress Test is something that everyone should be doing if you care about performance. I run software at AWS so is easy to spin up more boxes but is also more expensive and you might be in a trap because you might have ineffective software with Memory Leaks, Hidden Bugs, and untuned servers which will all show up with scale or stress tests - whatever happens first. Unfortunately, this still not quite popular among most of the microservices developers. Create and run stress tests is something hard and tedious because it involves lots of moving parts. A single microservice could call several other microservices some of the downstream dependency graphs could get complex easily, this is just one of the many challenges involved with stress tests. Today I want to share some experiences in building and running a stress test and chaos platform. Do you know how many concurrent users or requests per second(RPS) your microservices can handle? Do you know what it will be the COST to scal...

Reactive Programming with Akka Streams

Image
Akka-Streams is one of the many interesting and very useful Akka modules. Akka is a powerful actor / reactive framework for the JVM. Akka is an extremely high-performance library -- you can do Up to 50 million msg/sec on a single machine. Small memory footprint; ~2.5 million actors per GB of the heap. Akka is also resilient by Design and follows the principles of the Reactive Manifesto . Akka follows Erlang Actor philosophy/ideas.  Many big and successful companies use Akka in production like Blizzard, Intel, Wallmart, Paypal, Amazon, Zalando, Netflix, IGN, VMware UBS, and much many more others.

Running Multi-Nodes Akka Cluster on Docker

Image
Akka a great actor framework for the JVM.  Akka is high performance with high throughput and low latency, resilient by Design.  It's possible to use Akka with Java however I always used and recommend you use with Scala . Create actors systems is pretty easy however creating multiple nodes on Akka cluster locally could be boring and error-prone. So I want to show how easy is to create an Akka cluster using Scala and Docker (Engine & Docker-Compose). We will create a very simple actor system, we will just log events on the cluster however you can use this as a base to do more complex code.

The power of Scala Type Classes

Image
Scala language it was very inspired by Haskell . Type classes in another sample of this and many inspirations  from Haskell. There are always several ways and styles of thinking to address problems. Type classes is another way of thinking and dealing with problems. For some problems, you might just use Pattern Matcher -- But if you have to add a type? Right, I could stick with good old OO since Scala is hybrid right? --  But what if you need to add one operator? Type Classes can help you out.

My first book: Building Applications with Scala

Image
Dear reader, you might miss my post on the last 7 months. I was not posting with the same frequency I was doing before. The reason why it happened is because I was written a book about Scala. I'm here to announce my very first book about building Scala application. The book goes for the basic principle of functional and reactive programming to the most advance scala language ecosystem solutions such as Play Framework, Akka Framework, RxScala and much more.  I hope you enjoy the book and hope this book could help you in your career building scalable and modern scale applications. You can buy the book here: https://www.amazon.com/Building-applications-Scala-Diego-Pacheco/dp/178646148X Cheers, Diego Pacheco

Microservices Contracts: REST vs Native

Image
This is not a new discussion is very old. I remember back into the SOA days - always was something like REST VS SOAP. SOAP is dead and REST own but now is something different. To be clear - I think REST is the only thing you should use when we talk about External consumers. Like and external API thats would be accessed by a mobile or website. There are other scenarios like INTERNAL consumers. For this case you can consider using a NATIVE driver instead of REST. So whats is a NATIVE driver? Is just code into a language you are using - so could be Java, Scala, Clojure, Ruby, Go, whatever it does not matter. This idea is similar to the JDBC java driver you have java code to access the database.  So thats the real question when i have internal consumers for my microservices, should they talk to each other tought REST or native driver? It really depends because both approach have PROS and CONS like everything in life - there are trade offs - but i consider REST in general a ...

Microservices and Twitter Finagle

Image
Lots of people talk about microservices with REST and thats makes lots of sense because if we think about SOA and Service Orientation Principles we should have interoperability and Rest is great for that. Such task can be done be a edge service or proxy or api gateway so you really dont need use REST all the time internally. There is also 2 other important matters like performance for instance, use can use IPC and its way faster than HTTP calls. Second is do something in a JVM language like scala or java - you have benefits doing that. For instance you endup relying more in your compiler and this makes less tests needed and make ir easier to consume services.

Setting up a full JVM Env with Vagrant: Java 8, Scala 2.11, Groovy 2.4, Clojure 1.6, Maven 3.3, Gradle 2.4, Sbt 0.13 and Lein

Image
On the previous posts i show how to use docker , docker-compose and nodejs with vagrant now let`s do a full jvm env :-) This setup is pretty easy and straightforward for you however it could take some time depending of your internet bandwidth because we gonna download several components. Remember you need to have Vagrant installed already, this time we gonna need more than just the Vagrant file because java, scala, clojure for instance require we setup environment variables so we gonna need change some files for clojure and sbt  in order to make everything work smoothly.

Core FP Concepts slidecast

Image
Functional programing is growing a lot now a days, not only pure function programing languages but several new languages are hybrid or at lest had fp influences like java, javascript, c#, python.  On this slidecast i will talk about some of the core concepts on functional programing, here you want find all concepts but this could be a starting point for you. I hope you have fun :-)

Scala Package Objects

Image
So lets talk about this feature most people dont know scala has is the ability to use package objects. You might dont find that useful since you have do the same with different techniques but i think this is great for the granularity scala have to control visibility. You can use this feature to create DSL or simple to empower abstractions this feature is compiled so its safe but could lead to bad code if you dont use it with window. Because you can be sharing variables everywhere so this is really useful for module design but  as i sad you need o be careful.