score:2

Accepted answer

As @jrudolph pointed out, code inside non-leaf extraction directive (like inside pathPrefix("order" / IntNumber) { orderId => as it takes orderId parameter that is gonna be extracted from request) is executed per every request regardless wether or not directives inside are hitting the route. Code inside leaf-directive (like complete) is executed only when route matches.

To achieve what you probably want, just move your dbService.addParticipant inside complete:

pathPrefix("event" / Segment / "user") { id =>
    pathEnd {
        put {
            complete {
              dbService.addParticipant(id, user)
              "OK"
            }
        } ~
        delete {
            complete {
              dbService.removeParticipant(id, user)
              "OK"
            }
        }
    }
}

Related Query

More Query from same tag