pouya1364/probabilistic-bundle
A Laravel-friendly PHP package offering probabilistic data structures and helpers for approximate membership, counting, and cardinality estimation. Use it to build memory-efficient deduplication, caching, rate limiting, and analytics features with simple APIs when exact sets are too costly.
This is a Symfony bundle, not a Laravel package, so start by confirming how much of it you can use unchanged in a Laravel app.
composer require the bundle (and its pouya1364/probabilistic-php dependency).DependencyInjection/Configuration.php and *Extension.php first — that is the authoritative list of supported config keys and the only real "docs" at v0.1.0.ProbabilisticRegistry (your entry point for named instances) and the per-instance autowired service classes (the typed wrappers for each filter/sketch type).config/probabilistic.php and register the registry as a singleton in AppServiceProvider (see Gotchas — Symfony autowiring will not happen for you).First working call should look roughly like: resolve the registry, get('name') (or inject the specific instance service), then add()/has() on a Bloom, or add()/count() on a HyperLogLog. Verify with the probabilistic:list console command (via php bin/console, or register it as an Artisan command if you want artisan probabilistic:list).
Name instances by purpose, not by type. Config-driven naming is the whole value proposition:
signup_email_bloom -> BloomFilter
invite_dedup_bloom -> BloomFilter
daily_unique_visitors -> HyperLogLog
top_products_sketch -> CountMinSketch
session_dedup_cuckoo -> CuckooFilter
One instance per bounded use case keeps sizing and error rates honest and makes probabilistic:list a useful inventory of your probabilistic state.
Prefer the registry for dynamic access, typed services for fixed dependencies. Use ProbabilisticRegistry when the instance name is a variable (tenant ID, per-plan config); inject the concrete per-instance service when a class always needs the same filter — it keeps signatures explicit and testable.
Wrap it in your own thin service. Do not let ProbabilisticRegistry leak across your codebase. A single App\Support\Probabilistic wrapper (or a facade) gives you one place to swap the Symfony-coupled implementation, add logging, and stub it in tests.
Integrate at the edges of the request lifecycle:
add() for analytics counters instead of INSERT ... ON CONFLICT.Environment-sized config. Bloom filter size and hash count, HLL precision, and Count-Min width/depth belong in config with conservative defaults in config/probabilistic.php, overridable per environment. Treat these as capacity planning, not tuning knobs — changing them invalidates existing state.
Test against a real instance, not a mock. Mocks of a Bloom filter will lie to you about false positives. Build a tiny helper that constructs a fresh in-memory instance per test and assert on behavior ("rejects definitely-absent key"), not exact internals.
ProbabilisticServiceProvider, no facade, no publishable config in a Laravel sense. Expect to write a binding yourself and to copy the config tree rather than vendor:publish it.probabilistic-php for whether serialization helpers exist; if not, serialize the raw structure yourself and watch size.has() === false is authoritative, true is not. Never gate a refund, a delete, or a security check on a positive. Cuckoo filters have the same property plus possible insertion failure — handle the failure path rather than assuming add() always succeeds.probabilistic:list is your first tool to confirm which instances actually got registered — a typo'd name fails at lookup time, not at boot. For Laravel, register it as an Artisan command early; otherwise you are SSH-ing into bin/console.composer.json, and keep the Symfony-specific surface confined to your one wrapper class so an upstream API change is a single-file fix.How can I help you explore Laravel packages today?