title: Schedulers for network requests in RxSwift
body: <p>I’ve been learning Rxswift and applying it on a project since start. I would like your help to fell more assured about a concept.</p>
  
  <p>I understand the changes in the UI should be performed  on the Mainscheduler, and you should explicitly use <code>.observeOn(MainSchedule…</code> in case you don’t use <code>Drivers</code>.</p>
  
  <p>My doubt is: <strong>normally, should I explicitly switch to a background thread when performing  network requests?</strong>.</p>
  
  <p>I haven’t found many literature talking about exactly this, but I’ve read some projects code and most of them don’t, but a few do. Those eventually use <code>Drivers</code> or <code>.observeOn(MainSchedule…</code> to make the changes on the UI.</p>
  
  <p>In <a href="https://www.thedroidsonroids.com/blog/rxswift-examples-4-multithreading" rel="noreferrer">https://www.thedroidsonroids.com/blog/rxswift-examples-4-multithreading</a>, for instance, he says</p>
  
  <p><code>So as you may guessed, in fact everything we did was done on a MainScheduler. Why? Because our chain starts from searchBar.rx_text and this one is guaranteed to be on MainScheduler. And because everything else is by default on current scheduler – well our UI thread may get overwhelmed. How to prevent that? Switch to the background thread before the request and before the mapping, so we will just update UI on the main thread</code></p>
  
  <p>So what he does to solve the problem he mentions, is to explicitly declare
  <code>.observeOn(ConcurrentDispatchQueueScheduler(globalConcurrentQueueQOS: .Background))</code></p>
  
  <p>Assuming the API Request would be performed on background anyway, what this does is to perform all other computations in the background as well, right?</p>
  
  <p>Is this a good practice? <strong>Should I, in every API request, explicitly change to background and then changes back to Main only when necessary?</strong></p>
  
  <p><strong>If so, what would be best way?</strong> To observe on background and then on Main? Or to subscribe on background and observe on Main, as is done in this gist:
  <a href="https://gist.github.com/darrensapalo/711d33b3e7f59b712ea3b6d5406952a4" rel="noreferrer">https://gist.github.com/darrensapalo/711d33b3e7f59b712ea3b6d5406952a4</a>
  ?</p>
  
  <p>Or maybe another way?</p>
  
  <p>P.S.: sorry for the old code, but among the links I found, these better fit my question.</p>