# Sample

Published articles for Sample.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Comparing Java ZGC and G1 for Tail Latency in a Quarkus Microservice

DevFeed: [Comparing Java ZGC and G1 for Tail Latency in a Quarkus Microservice](<https://devfeed.tech/articles/let-s-take-a-look-at-lower-java-tail-latencies-with-zgc-18850.md>)

Original publisher: [Read original article](<https://www.morling.dev/blog/lower-java-tail-latencies-with-zgc/>)

Published: 2025-09-17T15:09:00Z

Content type: article

Language: en

Sources: [Gunnar Morling](<https://devfeed.tech/sources/gunnar-morling.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [benchmarking](<https://devfeed.tech/topics/benchmarking.md>), [Quarkus](<https://devfeed.tech/topics/quarkus.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [benchmarking](<https://devfeed.tech/tags/benchmarking.md>), [gc](<https://devfeed.tech/tags/gc.md>), [java](<https://devfeed.tech/tags/java.md>), [lts](<https://devfeed.tech/tags/lts.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [quarkus](<https://devfeed.tech/tags/quarkus.md>), [sample](<https://devfeed.tech/tags/sample.md>)

### AI overview

This article compares Java's ZGC and G1 garbage collectors using default settings in a sample Quarkus microservice that reads data from a Postgres database. The benchmark applies 1,000 requests per second and measures request latencies on a four-core, 4 GB RAM instance. The supplied excerpt does not include the comparison results.

### Source excerpt

Table of Contents ZGC Allocation Stalls Summary In the "Let's Take a Look at...!" blog series I am exploring interesting projects, developments and technologies in the data and streaming space. This can be KIPs and FLIPs, open-source projects, services, relevant improvements to Java and the JVM, and more. The idea is to get some hands-on experience, learn about potential use cases and applications, and understand the trade-offs involved. If you think there's a specific subject I should take a look at, let me know in the comments below. Java 25 was released earlier this week, and it is the first Java release with long-term support (LTS) which ships with Generational ZGC as the one (and only) flavor of the ZGC garbage collector. ZGC itself is a relatively new concurrent collector, originally added in Java 11.

## Kermit 2.0.5 updates OSLogWriter and adds file logging - Kevin Schildhorn

DevFeed: [Kermit 2.0.5 updates OSLogWriter and adds file logging - Kevin Schildhorn](<https://devfeed.tech/articles/kermit-2-0-5-updates-oslogwriter-and-adds-file-logging-kevin-schildhorn-38232.md>)

Original publisher: [Read original article](<https://touchlab.co/kermit-205>)

Published: 2024-11-22T00:00:00Z

Content type: release

Language: en

Sources: [Touchlab | Enterprise Mobile Innovation & Development](<https://devfeed.tech/sources/touchlab-enterprise-mobile-innovation-development.md>)

Topics: [Logging](<https://devfeed.tech/topics/logging.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [IO](<https://devfeed.tech/topics/io.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [file](<https://devfeed.tech/topics/file.md>)

Tags: [added](<https://devfeed.tech/tags/added.md>), [automatic](<https://devfeed.tech/tags/automatic.md>), [features](<https://devfeed.tech/tags/features.md>), [io](<https://devfeed.tech/tags/io.md>), [ios](<https://devfeed.tech/tags/ios.md>), [kermit](<https://devfeed.tech/tags/kermit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [library](<https://devfeed.tech/tags/library.md>), [logging](<https://devfeed.tech/tags/logging.md>), [logs](<https://devfeed.tech/tags/logs.md>), [module](<https://devfeed.tech/tags/module.md>), [sample](<https://devfeed.tech/tags/sample.md>), [swift](<https://devfeed.tech/tags/swift.md>), [update](<https://devfeed.tech/tags/update.md>), [updates](<https://devfeed.tech/tags/updates.md>)

### AI overview

Kermit 2.0.5 has been released with updates to OSLogWriter, an upgrade to Kotlin 2.0.10, and a new Kermit-IO module for writing logs to files. The release also adds configurable iOS log categorization, filtering, grouping, and public-versus-redacted log behavior.

### Source excerpt

The 2.0.5 update for Kermit is out now and features various updates to OSLogWriter, as well as the ability to log to a file.

## Jetpack Compose: A use case for view interop migration strategy - Jigar Brahmbhatt

DevFeed: [Jetpack Compose: A use case for view interop migration strategy - Jigar Brahmbhatt](<https://devfeed.tech/articles/jetpack-compose-a-use-case-for-view-interop-migration-strategy-jigar-brahmbhatt-38227.md>)

Original publisher: [Read original article](<https://touchlab.co/jetpack-compose-a-use-case-for-view-interop-migration-strategy>)

Published: 2023-02-08T12:00:26Z

Content type: tutorial

Language: en

Sources: [Touchlab | Enterprise Mobile Innovation & Development](<https://devfeed.tech/sources/touchlab-enterprise-mobile-innovation-development.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [migration](<https://devfeed.tech/topics/migration.md>), [SDK](<https://devfeed.tech/topics/sdk.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compose](<https://devfeed.tech/tags/compose.md>), [fragment](<https://devfeed.tech/tags/fragment.md>), [fragments](<https://devfeed.tech/tags/fragments.md>), [interop](<https://devfeed.tech/tags/interop.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [layout](<https://devfeed.tech/tags/layout.md>), [migration](<https://devfeed.tech/tags/migration.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [redesign](<https://devfeed.tech/tags/redesign.md>), [sample](<https://devfeed.tech/tags/sample.md>), [sdk](<https://devfeed.tech/tags/sdk.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

This article describes using Jetpack Compose with existing Android views and fragments during a sample app redesign for an SDK. It explains a Fragments-in-Compose approach, Compose navigation, SharedPreferences reuse, and adjustments needed for UI testing.

### Source excerpt

We had an opportunity to redesign the sample app for an SDK we're developing, using Jetpack Compose as part of our interop migration strategy.

## Magic Sprinkles at DevFest UK Ireland

DevFeed: [Magic Sprinkles at DevFest UK Ireland](<https://devfeed.tech/articles/magic-sprinkles-at-devfest-uk-ireland-32068.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/magic-sprinkles-at-devfest-uk-ireland/>)

Published: 2022-01-29T10:53:10Z

Content type: tutorial

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [ui](<https://devfeed.tech/topics/ui.md>), [API](<https://devfeed.tech/topics/api.md>)

Tags: [animate](<https://devfeed.tech/tags/animate.md>), [compose](<https://devfeed.tech/tags/compose.md>), [compose-animation](<https://devfeed.tech/tags/compose-animation.md>), [compose-ui](<https://devfeed.tech/tags/compose-ui.md>), [devfest](<https://devfeed.tech/tags/devfest.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [repo](<https://devfeed.tech/tags/repo.md>), [sample](<https://devfeed.tech/tags/sample.md>), [talk](<https://devfeed.tech/tags/talk.md>), [ui-components](<https://devfeed.tech/tags/ui-components.md>), [video](<https://devfeed.tech/tags/video.md>)

### AI overview

A shorter version of a DevFest UK Ireland talk introducing Jetpack Compose animations. It covers the animation API, simple quick-win animations, and more complex custom animations, with examples in a sample app and companion code repository.

### Source excerpt

A shorter version of my Magic Sprinkles talk presented at DevFest UK Ireland Magic Sprinkles: Adding animations to your app with Jetpack Compose I have some Jetpack Compose UI components in my app and now I want to add animations, where do I start? In this presentation I will look briefly at the Jetpack Compose animation api to get an overview of the animation system. Then I will look at a few quick win simple animations that can add some magic to your app. I will dive into more complex and custom animations to see what is possible. All of these experiments will be illustrated in a sample app provided in a companion repo. At the end of this talk you will: have an overview of how animation works in Jetpack Compose have some practical animation examples that you can add to your app immediately have an idea of what is possible with complex and custom animations have a code repo of examples Repo Slides Video

## Running Realm's Kotlin Multiplatform Sample App on Android and iOS | #TLTouchPoints - Justin Mancinelli

DevFeed: [Running Realm's Kotlin Multiplatform Sample App on Android and iOS | #TLTouchPoints - Justin Mancinelli](<https://devfeed.tech/articles/running-realm-s-kotlin-multiplatform-sample-app-on-android-and-ios-tltouchpoints-justin-mancinelli-38311.md>)

Original publisher: [Read original article](<https://touchlab.co/realm-kotlin-multiplatform-sample-app>)

Published: 2021-06-02T04:18:39Z

Content type: tutorial

Language: en

Sources: [Touchlab | Enterprise Mobile Innovation & Development](<https://devfeed.tech/sources/touchlab-enterprise-mobile-innovation-development.md>)

Topics: [Kotlin Multiplatform](<https://devfeed.tech/topics/kotlin-multiplatform.md>), [Android](<https://devfeed.tech/topics/android.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [Mobile](<https://devfeed.tech/topics/mobile.md>), [multiplatform](<https://devfeed.tech/topics/multiplatform.md>), [App](<https://devfeed.tech/topics/app.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [app](<https://devfeed.tech/tags/app.md>), [ios](<https://devfeed.tech/tags/ios.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [mobile](<https://devfeed.tech/tags/mobile.md>), [multiplatform](<https://devfeed.tech/tags/multiplatform.md>), [sample](<https://devfeed.tech/tags/sample.md>), [touchlabshare](<https://devfeed.tech/tags/touchlabshare.md>)

### AI overview

A Touchlab Touchpoints episode demonstrates running Realm's Kotlin Multiplatform sample app on Android and iOS, while discussing Realm's history and MongoDB's mobile strategy.

### Source excerpt

In this episode of Touchlab Touchpoints with Justin Mancinelli, we get Realm's Kotlin Multiplatform sample app running on Android and iOS

## Ruby vs Rails

DevFeed: [Ruby vs Rails](<https://devfeed.tech/articles/ruby-vs-rails-28306.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2020/02/10/ruby-vs-rails.html>)

Author: Fuzzygroup

Published: 2020-02-10T00:00:00Z

Content type: article

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [Kafka](<https://devfeed.tech/topics/kafka.md>), [X (Twitter)](<https://devfeed.tech/topics/twitter.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [data](<https://devfeed.tech/tags/data.md>), [kafka](<https://devfeed.tech/tags/kafka.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [sample](<https://devfeed.tech/tags/sample.md>), [vs](<https://devfeed.tech/tags/vs.md>)

### AI overview

The article explains Rails-specific methods that can cause failures when Ruby code runs outside Rails. Using a background daemon that streams Twitter data to Kafka, it examines the undefined `blank?` method in pure Ruby and the Rails-provided `second` method on arrays, then shows Ruby-compatible alternatives.

### Source excerpt

I always find it interesting when I hit a Rails-ism when I'm working in a pure Ruby context. I define a Rails-ism as something that is one way in Ruby and another way in Rails. In this case I'm writing a simple background daemon which is going to stream data out of the Twitter sample stream and commit to Kafka for downstream processing. Here's the first thing that bit me: TOPIC = ENV['TOPIC'] if TOPIC.blank? puts "No topic specified; exiting" exit end And this gave an immediate failure: ❯ TOPIC=twitter RAILS_ENV=development ruby kafka_loader.rb Traceback (most recent call last): kafka_loader.rb:19:in `<main>': undefined method `blank?' for "twitter":String (NoMethodError) The easiest way to understand something like this is to test it in irb. The irb tool is the underlying engine in rails console ("rails c") but without your application specific classes loaded in so it is just pure ruby. Here's how you would test something like this in irb: 2.7.0 :001 > "".blank? Traceback (most recent call last): 16: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors' 15: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/bundler-2.1.2/libexec/bundle:46:in `block in <top (required)>' 14: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cli.rb:24:in `start' 13: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start' 12: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch' 11: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch' 10: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command' 9: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run' 8: from /Users/sjohnson/.rvm/rubies/ruby-2.7.0/lib/ruby/2.7.0/bundler/cl

## Modularization - Real-life example

DevFeed: [Modularization - Real-life example](<https://devfeed.tech/articles/modularization-real-life-example-28679.md>)

Original publisher: [Read original article](<https://jeroenmols.com/blog/2019/04/02/modularizationexample/>)

Author: info@jeroenmols.com (Jeroen Mols)

Published: 2019-04-02T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jeroen Mols](<https://devfeed.tech/sources/jeroen-mols.md>)

Topics: [modules](<https://devfeed.tech/topics/modules.md>), [navigation](<https://devfeed.tech/topics/navigation.md>), [App](<https://devfeed.tech/topics/app.md>), [test](<https://devfeed.tech/topics/test.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [blogs](<https://devfeed.tech/tags/blogs.md>), [code](<https://devfeed.tech/tags/code.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [modularization](<https://devfeed.tech/tags/modularization.md>), [modules](<https://devfeed.tech/tags/modules.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [sample](<https://devfeed.tech/tags/sample.md>), [software-engineering](<https://devfeed.tech/tags/software-engineering.md>), [test](<https://devfeed.tech/tags/test.md>)

### AI overview

This tutorial presents a practical example of a multi-module application architecture. It examines the resulting application structure, navigation graphs, staged rollouts, testing, and a production application using the architecture.

### Source excerpt

With a clear view on how multi-module apps should be architected, let's dive into a real-life practical example. We'll discover how the architecture results in a clear application structure, how navigation is handled, how to use staged rollouts, how to test everything and even look at a production app that is using this architecture.

## Note to future me -- Adding GraphQL to an app

DevFeed: [Note to future me -- Adding GraphQL to an app](<https://devfeed.tech/articles/note-to-future-me-adding-graphql-to-an-app-32072.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/note-to-future-me-adding-graphql-to-an-app/>)

Published: 2018-04-08T21:36:13Z

Content type: tutorial

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [GraphQL](<https://devfeed.tech/topics/graphql.md>), [API](<https://devfeed.tech/topics/api.md>), [JSON](<https://devfeed.tech/topics/json.md>), [JSON Schema](<https://devfeed.tech/topics/json-schema.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [graphql](<https://devfeed.tech/tags/graphql.md>), [json](<https://devfeed.tech/tags/json.md>), [json-schema](<https://devfeed.tech/tags/json-schema.md>), [node](<https://devfeed.tech/tags/node.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [query](<https://devfeed.tech/tags/query.md>), [sample](<https://devfeed.tech/tags/sample.md>)

### AI overview

A practical note on adding GraphQL to an application: install and run a Node service, obtain its schema with Apollo Codegen, add a query and schema to the app, and call the service.

### Source excerpt

Adding the library to the app see commit 03bd7a7534f7a23276fc47c4f7c94d7ac153bc0b plugin dependencies Making a service wrapping and existing endpoint https://github.com/joakin/wikimedia-graphql install node if you don't have it. node -- version running the service `node index.js` play with the service https://gist.github.com/maiatoday/578aebcee3bd9decb6e3c6833c73a4ba#file-wikipage-graphql getting the json.schema https://github.com/apollographql/apollo-codegen cd app/src/main/graphql/net/maiatoday/helloblondie apollo-codegen download-schema http://localhost:3002/graphql -- output schema.json Adding the service to the app adding a query adding the schema a5a47f0ff45f6bc5d5a3aa6f1fee50af363f7893 getting access to the service calling the service Some pointers on query syntax Gitrepo `sudo apollo-codegen introspect-schema https://api.blargh.com/graphql -- header "Authorization: Bearer xxxx" -- output schema.json`

## Neotaur-Geotaur

DevFeed: [Neotaur-Geotaur](<https://devfeed.tech/articles/neotaur-geotaur-32070.md>)

Original publisher: [Read original article](<https://www.maiatoday.net/p/neotaur-geotaur/>)

Published: 2016-08-29T12:04:46Z

Content type: article

Language: en

Sources: [maiatoday](<https://devfeed.tech/sources/maiatoday.md>)

Topics: [App](<https://devfeed.tech/topics/app.md>), [Firebase](<https://devfeed.tech/topics/firebase.md>), [Google](<https://devfeed.tech/topics/google.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [firebase](<https://devfeed.tech/tags/firebase.md>), [google](<https://devfeed.tech/tags/google.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [logging](<https://devfeed.tech/tags/logging.md>), [sample](<https://devfeed.tech/tags/sample.md>), [with](<https://devfeed.tech/tags/with.md>)

### AI overview

A short project note about Neotaur-Geotaur, a sampler app that compares Google location APIs with Awareness APIs using the same geofences. It also mentions Firebase remote logging and database access, plus dependency injection.

### Source excerpt

I like to make sampler apps to explore new things to learn. I was wondering how the google location apis differed from the new awereness apis. The Geotaur repo has an app that can use either of these two interfaces. Since it builds two flavours you can run the apps side by side with the same geofences to see how they differ. While I was at it I tried my hand at some other tech too, firebase remote logging and db access, dependency injection. Install from play: Neotaur{:target="_blank"} Geotaur{:target="_blank"}

## Upstream Messages With Google Cloud Messaging

DevFeed: [Upstream Messages With Google Cloud Messaging](<https://devfeed.tech/articles/upstream-messages-with-google-cloud-messaging-29126.md>)

Original publisher: [Read original article](<https://www.grokkingandroid.com/upstream_messages_with_google_cloud_messaging/>)

Author: Wolfram Rittmeyer

Published: 2014-02-06T08:39:14Z

Content type: tutorial

Language: en

Sources: [Grokking Android](<https://devfeed.tech/sources/grokking-android.md>)

Topics: [Messaging](<https://devfeed.tech/topics/messaging.md>), [Android](<https://devfeed.tech/topics/android.md>), [API](<https://devfeed.tech/topics/api.md>), [Google](<https://devfeed.tech/topics/google.md>), [GitHub](<https://devfeed.tech/topics/github.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api](<https://devfeed.tech/tags/api.md>), [ccs](<https://devfeed.tech/tags/ccs.md>), [cloud-connection-server](<https://devfeed.tech/tags/cloud-connection-server.md>), [github](<https://devfeed.tech/tags/github.md>), [google](<https://devfeed.tech/tags/google.md>), [google-cloud-messaging](<https://devfeed.tech/tags/google-cloud-messaging.md>), [messaging](<https://devfeed.tech/tags/messaging.md>), [sample](<https://devfeed.tech/tags/sample.md>), [tutorials](<https://devfeed.tech/tags/tutorials.md>), [upstream-messaging](<https://devfeed.tech/tags/upstream-messaging.md>), [user-notifications](<https://devfeed.tech/tags/user-notifications.md>)

### AI overview

This tutorial explains upstream messaging with Google Cloud Messaging on Android. It introduces the messaging model, describes the Android-side event flow, and points to sample client and server applications. The article focuses on sending messages from a device to Google's cloud and is part of a series that also covers server-side processing and user-specific notifications.

### Source excerpt

Google announced a new messaging model with Google Cloud Messaging on last years Google IO. This model allows for upstream messaging and for user specific notifications. This post is the first in a three-part series in which I am going to look into both these changes and to show you how to use them. I [...] Continue Reading "Upstream Messages With Google Cloud Messaging" The post Upstream Messages With Google Cloud Messaging appeared first on Grokking Android.

## Reservoir Sampling

DevFeed: [Reservoir Sampling](<https://devfeed.tech/articles/reservoir-sampling-40325.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2013/07/05/reservoir-sampling/>)

Published: 2013-07-05T10:00:49Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Algorithm](<https://devfeed.tech/topics/algorithm.md>), [Python](<https://devfeed.tech/topics/python.md>), [data](<https://devfeed.tech/topics/data.md>), [datasets](<https://devfeed.tech/topics/datasets.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [big-data](<https://devfeed.tech/tags/big-data.md>), [generator](<https://devfeed.tech/tags/generator.md>), [induction](<https://devfeed.tech/tags/induction.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [random](<https://devfeed.tech/tags/random.md>), [randomized-algorithm](<https://devfeed.tech/tags/randomized-algorithm.md>), [reservoir-sampling](<https://devfeed.tech/tags/reservoir-sampling.md>), [sample](<https://devfeed.tech/tags/sample.md>), [streaming-algorithms](<https://devfeed.tech/tags/streaming-algorithms.md>), [streaming-data](<https://devfeed.tech/tags/streaming-data.md>), [streams](<https://devfeed.tech/tags/streams.md>)

### AI overview

This tutorial explains reservoir sampling for selecting an item uniformly at random from a data stream whose size is unknown or too large to store in memory. Its Python algorithm keeps one item and replaces it at step k with probability 1/k, with an induction-based proof of uniform selection.

### Source excerpt

Problem: Given a data stream of unknown size $ n$, pick an entry uniformly at random. That is, each entry has a $ 1/n$ chance of being chosen. Solution: (in Python) import random def reservoirSample(stream): for k,x in enumerate(stream, start=1): if random.random() < 1.0 / k: chosen = x return chosen Discussion: This is one of many techniques used to solve a problem called reservoir sampling. We often encounter data sets that we'd like to sample elements from at random.