Hi Everyone. Just a quick note to announce that w...
# http4k
d
Hi Everyone. Just a quick note to announce that we have now released a new version of http4k and http4k-connect which support AWS Lambda Snapstart. Also, there was Kotlin meet-up in London yesterday with talks by Andrey Breslav (Kotlin language designer) and myself. The event was live-streamed and you can find the details below. Andrey's talk was especially interesting as it delved into the sources of inspiration for the Kotlin design (and more importantly what features were left out and why! 🙂 ): Details Andrey Breslav (@1h15m) Andrey Breslav led the design and development of the Kotlin Programming Language at JetBrains for 10 years. Andrey will be talking about the languages Kotlin learned from and will have plenty of time for Q and A - so prepare questions you'd like to ask the lead language designer of Kotlin :) David Denton: Smash Your Adapter Monolith With The Connect Pattern (@0h15m) Server-side code is regularly broken down into manageable chunks, based on endpoints. As a result, it tends to be nicely factored. But over several projects, we noticed that the same was not true of adapters that talk to 3rd party systems. These pieces of code tended to grow uncontrolled and were not given the same level of attention. We can use the power of Kotlin and take advantage of language features such as Data Classes, Companion Objects, Operator Overloading and Extension Functions to easily do this - but the pattern concepts themselves are applicable to any technology choice or programming model. You can watch it online here:

https://youtu.be/JgmzgsNYgXgâ–¾

K 9
K 4
h
Hey @dave and @s4nchez, In the GitHub issue in which you've made http4k SnapStart possible I promised to follow up on this. Thank you for enabling this feature. We already reduced the coldstart of fetching an S3 file + URL from 2,4 seconds to 1,2 seconds. In the meantime AWS is helping us to reduce this further as they are getting 700ms in their cold start tests (without frameworks). So thanks for your effort!
d
v cool! @Harmen Backhaus which HTTP client are you using for the S3 access? If you haven't already, then suggest going with the stock JavaHttpClient() as that doesn't have connection pooling.
h
Ah good to hear. All the credits for the code go to my colleague, we now have the following. A service calls this function:
Copy code
val webClient = WebclientFactory
        .createWebClient(baseUrl = Environment.getEnvironment("BACKENDS_<Obfuscated-external-service>_BASEURL"), circuitBreaker = CIRCUIT_BREAKER)
        .then(OkHttp())

    fun getDisruptions(active: Boolean): List<Disruption> =
        disruptionsResponseLens(
            webClient(
                Request(Method.GET, "/api/v3/disruptions?type=disruption&type=maintenance")
                    .query("isActive", active.toString())
            )
        )

    companion object {
        private val disruptionsResponseLens = Body.auto<List<Disruption>>().toLens()
        private val CIRCUIT_BREAKER = CustomCircuitBreakerConfig.getCircuitBreaker("<Obfuscated-external-service>")
    }
After that the same service use .filter to further process this:
Copy code
.filter { disruption -> disruption.publicationSections.isNotEmpty() }
            .filter { disruption ->
                // Filter disruptions and maintenance within the given period
                if (startDate != null && disruption.timespans.none { timespan -> timespan.start?.isAfter(startDate) == true }) {
                    return@filter false
                }

                if (endDate != null && disruption.timespans.none { timespan -> timespan.end?.isBefore(endDate) == true }) {
                    return@filter false
                }

                id.isNullOrBlank() || id == disruption.id
            }
            .flatMap { disruption ->
                disruption.publicationSections
                    .map { section -> service.trajectToFeature(section, disruption.id, disruption.type) }
            }
I'm not that deep into Kotlin as I'm helping my colleague from an AWS Cloud perspective, I do however enjoy learning about this 🙂.
I'll suggest to switch to JavaHttpClient() @dave, so thank you for your suggestion
d
np. If you're using anything with log4j or Jackson that's also a big penalty
h
We do use org.slf4j.LoggerFactory for logging to CloudWatch logs. Not sure if that's a big penalty as well.
d
System.println + structured logging (with moshi) FTW! 😂
h
Ah okay,, I'll also share that with my colleague, it could now be the case that we get to the 700ms without AWS's help 😉
j
Not related to lambdas, but the way that the query url is built up... could be done differently. Using strings to build uris is fraught with problems. I'd suggest use the query parameter api to build that, and also not rely on the particular "toString" of Boolean to give you the "false" that the api seems to want.
h
Hey @James Richardson, Thank you so much for suggesting better ways to code this and sorry for taking such a long time to respond. I'll look at this with my colleague.