assaf / vanity

Experiment Driven Development for Ruby
http://vanity.labnotes.org
MIT License
1.55k stars 269 forks source link

Prevent dupe participation in same experiment #335

Closed pihman closed 6 years ago

pihman commented 6 years ago

There's a race condition that can lead to duplicate participation -- and possibly conflicting segmentation -- for a given experiment.

Thread A: Vanity.ab_test(:my_experiment)

Thread B: Vanity.ab_test(:my_experiment)


To prevent this situation:

1) Make the existing (experiment_id, identity) index a unique index. 2) Update the Vanity::Participant code to gracefully handle the dup record failure.

phillbaker commented 6 years ago

Thanks for the PR, it'll take me a day or two to review.

pihman commented 6 years ago

@phillbaker I un-mixed up the migrations. Thanks!