Optimistic UI is a UX technique to reduce waiting time for the user resulting in a much smoother and faster app experience. It is mainly used when communicating with APIs which usually takes a certain amount of time. Before the client sends a request it guesses the response and updates the UI in advance. When the server responds as expected the client has nothing to do and the user did not have to wait for the response. In case of errors or unexpected responses the client has to adjust the UI which can be irritating for the user. Thus it is important to know or predict what the server will do to have as few corrections as possible.
Note: Do not use optimistic UI for longer tasks. If the user queues up long tasks data inconsistencies could occur. Also it can be useful for the user to know if a tasks takes longer.