Posts

Showing posts from June, 2020

zio streams + scala.js: example of designing a streaming db API

zio streams + scala.js: example of designing a streaming db API nodejs has a streams API. However, if you are using zio with scala.js, you may want to use zstreams. To use zstreams, you will need to adapt your APIs. The content below was inspired by a recent zio stream Itamar training video: https://www.youtube.com/watch?v=XIIX2YSg7M0 While scala.js is used below on nodejs, as always, scala.js has such good conformance to scala that you cannot really tell its javascript except for the use of javascript APIs. The example below adapts a javascript streaming API to scala.js and zio’s zstreams. It makes certain tradeoffs to reduce implementation time to a few minutes (the time it takes to write a blog). Generally, since its javascript, we don’t need to worry about parallelism. Ideally, we would write something whose pattern could be moved over to the jvm or another platform where parallelism is possible. Here are some good resources on zio streams: zio manual: ht

vertically scaling nodejs: dotty + graaljs + zio

vertically scaling nodejs: dotty + graaljs + zio You can horizontally or vertically scale. Horizontal scaling usually involves running multiple separate process either on the same compute server or on different servers. It is relatively complex to scale horizontally if you need to share state. Engineers often scale horizontally and decouple different data “domains” into micro-services, both of which can also be more complex to engineer. Cloud compute services and frameworks like Kubernetes help you scale horizontally but at, potentially, a large increase in complexity. You can also scale vertically. Multi-threaded programming is harder than single threaded programming. Python and nodejs are loved by developers because they make the compute enviroment simpler, and hence, the programming simpler. nodejs has asynchronous programming support via ES “await” syntax or js Promises, both of which are harder to use than straight procedural code. But, most developers have f

quick note on dotty, graaljs interop: structural typing with Selectable

quick note on dotty, graaljs interop: structural typing with Selectable This is a quick note on dotty’s structural typing via Structural and graaljs interop. graaljs is nodejs on the graal vm with interop to JVM. You can run dotty as the JVM language quite easily, just like any other JVM language. Dotty has a new feature for structural typing ( https://dotty.epfl.ch/docs/reference/changed-features/structural-types.html ) based on the Selectable trait. It implements a dynamic lookup to values based on application specific metadata. The example given on the web site is: case class Record ( elems : ( String , Any ) * ) extends Selectable { def selectDynamic ( name : String ) : Any = elems . find ( _ . _1 == name ) . get . _2 } type Person = Record { val name : String val age : Int } val person = Record ( "name" - > "Emma" , "age" - > 42 ) . asInstanceOf [ Person ] println ( s &quo

zio layers and framework integration

zio layers and framework integration https://github.com/zio/zio is a FP library for scala. When used to organize your entire program, your main function inherits from the zio App and you return a zio effect ( ZIO ). You don’t need to worry about creating a default environment or other such details. This blog touches on using zio in an existing framework and composes services using ZLayer . When zio is inserted into an existing framework, the setup is different. We will add zio to an existing javascript app stack with only a few lines of extra “glue” code–that’s how easy it is. If your app is not complex, you should stick with javascript/typescript and async/await or stick with composing js.Promise in scala.js–they are good enough for a wide range of work. If you have something more complicated, read on. Some useful ZLayer blogs: https://timpigden.github.io/_pages/zlayer/Examples.html?utm_campaign=ZIO News&utm_medium=email&utm_source=Revue newslet