Prev Next

Spring / Spring Webflux Interview questions

What is the difference between flatMap, concatMap, and switchMap?

  • flatMap: Subscribes to inner publishers eagerly and flattens them. It does not preserve the original order of elements (they are interleaved/asynchronous).
  • concatMap: Similar to flatMap but waits for each inner publisher to complete before starting the next one. It preserves order but is slower because it is sequential.
  • switchMap: Every time a new element arrives from the source, it cancels the previous inner subscription and starts a new one. Ideal for search-as-you-type scenarios.

More Related questions...

Show more question and Answers...


Comments & Discussions