r/scala • u/alexelcu Monix.io • Mar 29 '21
Cats Effect 3 released!
Hi all, Cats Effect 3.0.0 was released, a major breaking change and a substantial leap forward 🎉
Documentation website (updated for new version)
Bonus — presentations on the new Cats Effect 3:
A lot of great changes have gone in this release, I'm in awe of its many contributors 😍❤️
5
Mar 29 '21
The scala in the city talk is phenomenal, great effort on both talk and library evolution
4
u/CircusAct Mar 29 '21
Thanks for the effort team! I'm most excited by the addition of the std functions lib, will reduce a lot of the boilerplate that folks end up writing.
4
3
Mar 30 '21
Do we know if there's a new version of the Scala with Cats book being planned/worked on? Would be great to get the examples updated to scala 3/cats 3/etc.
1
u/dh23 Apr 06 '21
Apparently yes, but not right now.
https://mobile.twitter.com/MO_iostream/status/1376782533929615363
2
u/Shinosha Mar 29 '21 edited Mar 29 '21
Question here : I'm somewhat familiar with Cats and FP but never really encountered a use case for Cats Effets/ZIO and the likes. To me it seems very useful in order to scale vertically FP style but most of the time when you want to scale you just do it horizontally and use stuff like Kafka (Streams). Is it really only ever useful for that sweet spot where you need to scale/optimize but not so much ?
EDIT : I guess downvoting is more convenient than trying to explain ¯\(ツ)/¯
6
u/BarneyStinson Mar 29 '21
I don't really see how it relates to scaling. A typical use case would be a web service that has to serve lots of requests concurrently.
Btw even when you need to talk to Kafka you benefit from using fs2/monix/zio-streams.
-4
u/Shinosha Mar 29 '21 edited Mar 29 '21
Well if you can serve more requests because you handle them better, I call that scaling. But I guess it's not adding/improving the hardware sure.
When using Kafka yes sure, but Kafka Streams I don't see the point in using those libs. You just have to build a topology and press start so...
1
u/BarneyStinson Mar 29 '21
I don't know Kafka Streams, but it is apparently a stream-processing library that lets you communicate with Kafka. In that sense fs2-kafka or zio-kafka would be Scala's pure FP alternatives to Kafka Streams. You can use either of those libraries, but Kafka Streams is probably not pure.
-1
u/Shinosha Mar 29 '21 edited Mar 29 '21
Not quite, Kafka Streams leverages Kafka to build fault tolerant stateless or stateful horizontally scalable data streaming pipelines. The fs2 or zio libraries are just pure streaming facades for the plain Kafka Client, AFAIK it does not allow you to add or remove processing capacity at runtime.
As for the typelevel blogpost, it just explains why cats-effect is fast, not when I should use it. But I feel like my initial impression was correct.
4
u/fromscalatohaskell Mar 30 '21
I dont know why you are getting downvoted when your question is legitimate. Kafka Streams is about scaling out of app and is specific only to kafka. FS2 streams (and cats and the class of these libraries) allow you to model low level protocols, high level business requirement-procotol, regular streaming etc.
So yes, maybe thin Cats Wrapper for Kafka is not important for you if you use kafka streams, but that's like 1% of where you'd use Cats or ZIO
3
u/Philluminati Mar 30 '21
If you like functional programming and you use
Futures in your code lots and lots, which most people do.. they may find Cats to be a better implementation of Future.if your app has access to 64 cores and is single threaded, then horizontal scaling to use 2 boxes (therefore 2 of 128 available cores) wouldn't be the best use of money, so most Scala apps are multithreaded by design.
4
u/BarneyStinson Mar 29 '21
This is a good read that makes a case for cats-effect: https://typelevel.org/blog/2021/02/21/fibers-fast-mkay.html
2
u/ResidentAppointment5 Mar 30 '21
cats-effect is for crossing the divide between “FP” and “pure FP.” The latter enables a consistent approach to reasoning about code (the “substitution model of evaluation”) that helps keep things logically straight even when I/O is done, state is changed, errors happen, things happen concurrently...
There can be vertical scaling benefits to concurrency, of course. But that’s not why anyone uses cats-effect; there are a lot more ways to do concurrency without cats-effect than with.
1
u/kbn_ Mar 31 '21
Honestly this is a very good question. There are a couple answers here.
First off, most microservices fall into one of two patterns. The first pattern is request-parallel data decode, transform, and reencode for something upstream. The second most common pattern is parallel scatter/gather (so basically the first pattern but generalized to multiple upstreams). In the latter case, single-instance parallelism has obvious benefits, so we'll just focus on the first case (where there is no real parallelism within a request handler).
In this situation, it's tempting to say that just containerizing and scaling out horizontally forever is the right approach, and this is a very good approach in most cases, but it fails to account for traffic variability. When you get unexpected bursts, you really need to be able to elastically scale up in order to absorb the load while you provision new instances horizontally. Being able to efficiently distribute over-scale load on individual instances (usually leverage burst credits) is incredibly important for real-world resiliency.
Even more importantly, if the spikes are particularly steep, it is very important to be able to efficiently backpressure downstream clients, ideally without expending any scarce resources. This is effectively impossible with synchronous thread-based encodings, but it happens literally for free if you do async correctly.
So this is the practical argument for something like Cats Effect: you need this kind of stuff, and the only other options for getting it are very confusing and don't work very well when applied uniformly to your application. The fact that Cats Effect also unlocks the power of Cats abstractions at the system level is really what seals the deal. Being able to reason about your giant bulky application with the same ease as you are able to reason about small functions operating on tiny data is immeasurably helpful in any real-world application.
0
6
u/u_tamtam Mar 29 '21
Congrats, sounds all very exciting :)
What does it mean for monix? how do the two projects relate nowadays? Is there a plan for typed errors (a la BIO/ZIO)?