ActiveStorage service Thread safety

Is ActiveStorage.service thread safe ? Does anyone have any suggestion about setting different services for each tenant? I’d like to have something like

before_action do
  ActiveStorage::Blob.service = *config based on tenant*

But I see .service is only class accessor which means it could be overwritten in multi-thread PUMA requests? What’s the best approach for having multiple storage locations (1 for each tanant)


  • Request1: changes the service: ActiveStorage::Blob.service = tenant1
  • Request2: changes the service: ActiveStorage::Blob.service = tenant2
  • Request1: reads some file: ActiveStorage::Blob.first

Will it read correct file? So the change of service from Request2 does not affect Request1